Public Type RASPPPIP
'set dwsize to 40
dwSize As Long
dwError As Long
szIpAddress(RAS_MaxIpAddress) As Byte
szServerAddress(RAS_MaxIpAddress) As Byte
End Type
Public Declare Function RasGetProjectionInfo Lib "RasApi32.DLL" Alias "RasGetProjectionInfoA" (ByVal hRasConn As Long, ByVal rasprojection As Long, lpprojection As Any, lpcb As Long) As Long
Private Function TrimNull(StrNull As String) As String
Dim l As Long
l = InStr(StrNull, vbNullChar)
If l > 0 Then
TrimNull = Left$(StrNull, l - 1)
Else
TrimNull = StrNull
End If
End Function
...
Dim lpraspppip As RASPPPIP
lpraspppip.dwSize = 40
If RasGetProjectionInfo(mhConn, RASP_PppIp, lpraspppip, 40) = 0 Then
mRemoteIPAddress = TrimNull(StrConv(lpraspppip.szServerAddress, vbUnicode))
End If
Dim lpraspppip As RASPPPIP
lpraspppip.dwSize = 40
If RasGetProjectionInfo(mhConn, RASP_PppIp, lpraspppip, 40) = 0 Then
mRemoteIPAddress = TrimNull(StrConv(lpraspppip.szServerAddress, vbUnicode))
End If
试试下面这个函数,返回的就是你的当前ip,如果你同时还有网卡的话,那么你就要在获取result的时候判断一下,他获取的是当前的所有ip,只要稍加比较就可以找到你要的拨号ip, if result=yourip(lan) then ...
function TForm1.LocalIP : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;