高分求解:Delphi编程如何知道硬件网关的WAN IP呢?(100分)

  • 主题发起人 主题发起人 peterzhou20
  • 开始时间 开始时间
P

peterzhou20

Unregistered / Unconfirmed
GUEST, unregistred user!
局域网通过硬件网关上网,想在局域网中知道当前的WAN IP,不知道用DELPHI如何实现?
 
procedure TForm1.Button1Click(Sender: TObject);
var
wVersionRequested : WORD;
wsaData : TWSAData;
p : PHostEnt;
s : array[0..128] of char;
p2 : pchar;
hostName,hostIP:String;
begin
{Start up WinSock}
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);

{Get the computer name}
GetHostName(@s, 128);
p := GetHostByName(@s);

{Get the IpAddress}
p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);

hostName:=p^.h_Name;
hostIP:=p2;
showmessage(hostname+hostip);
WSACleanup;
end;
 
执行
WSAStartup(wVersionRequested, wsaData);
发生如下错误:
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 00000000. Read of address 00000000'. Process stopped. Use Step or Run to continue.
 
后退
顶部