function GetLocalIPs: String; type PPInAddr= ^PInAddr; var wsaData: TWSAData; HostInfo: PHostEnt; HostName: Array[0..255] of Char; Addr: PPInAddr; begin Result:=''; if WSAStartup($0101, wsaData)<>0 then exit; try if gethostname(HostName, SizeOf(HostName)) <> 0 then exit; HostInfo:= gethostbyname(HostName); if HostInfo=nil then Exit; Addr:=Pointer(HostInfo^.h_addr_list); if (Addr=nil) or (Addr^=nil) then exit; Result:=StrPas(inet_ntoa(Addr^^)); inc(Addr); while Addr^<>nil do begin Result:=Result+^M^J+StrPas(inet_ntoa(Addr^^)); inc(Addr); end; finally WSACleanup; end; end;用这个function获得IP地址,再发送出去。
ClientSocket->Socket->LocalAddress得到。
type PPInAddr= ^PInAddr;
var
wsaData: TWSAData;
HostInfo: PHostEnt;
HostName: Array[0..255] of Char;
Addr: PPInAddr;
begin
Result:='';
if WSAStartup($0101, wsaData)<>0 then exit;
try
if gethostname(HostName, SizeOf(HostName)) <> 0 then exit;
HostInfo:= gethostbyname(HostName);
if HostInfo=nil then Exit;
Addr:=Pointer(HostInfo^.h_addr_list);
if (Addr=nil) or (Addr^=nil) then exit;
Result:=StrPas(inet_ntoa(Addr^^));
inc(Addr);
while Addr^<>nil do begin
Result:=Result+^M^J+StrPas(inet_ntoa(Addr^^));
inc(Addr);
end;
finally
WSACleanup;
end;
end;用这个function获得IP地址,再发送出去。