在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
安装Indy uses IdStackWindows; var Isw:TIdStackWindows; slist:TStringList; begin Isw:=TIdStackWindows.Create; slist:=TStringList.Create; try Isw.AddLocalAddressesToList(slist);//这个方法可以取出IP finally FreeAndNil(Isw); FreeAndNil(slist); end; end; 另外一种方法:
var sck: TIdStackWindows; address: TIdStackLocalAddressList; begin sck := TIdStackWindows.Create; address := TIdStackLocalAddressList.Create; try sck.GetLocalAddressList(address); for i := 0 to address.Count - 1 do begin if address[i].IPVersion in [Id_IPv4] then //过滤IP_V6 begin Item.Caption := address[i].IPAddress; //item是其他变量 end; end; finally FreeAndNil(sck); FreeAndNil(address); end; end XE10.x 使用正常
D2010 function GetLocalIP(Multi: Boolean = False): string; type PPInAddr = ^PInAddr; //取本机IP,可取多个(分行列出) 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) and Multi do begin Result := Result + ^M^J+ StrPas(inet_ntoa(Addr^^)); inc(Addr); end; finally WSACleanup; end; end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论