uses windows ,winsock;<br><br>procedure GetHostInfo(var HostName,IPAddress:string);<br>{ 入口:两个字符串指针(传址)<br> hostname 指向本机主机名的字符串<br> IPAddress 指向本机IP地址的字符串<br>出口:同入口<br>}<br><br>procedure GetHostInfo(var HostName,IPAddress:string);<br>var<br> WSAData :TWSAData;<br> HostEnt: PHostEnt;<br>begin<br> WSAStartup(2,WSAData);<br> SetLength(HostName,255);<br> GetHostName(PChar(HostName),255);<br> SetLength(HostName, StrLen(PChar(HostName)));<br> HostEnt :=gethostbyname(PChar(HostName));<br> with HostEnt^ do<br> begin<br> IPAddress := Format('%d.%d.%d.%d',<br> [Byte(h_addr^[0]),<br> Byte(h_addr^[1]),<br> Byte(h_addr^[2]),<br> Byte(h_addr^[3])<br> ]<br> );<br> end;//with<br> WSACleanup;<br>end;