获取本地IP地址 uses WinSock, SysUtils;<br><br>type ESockUtilErr = Class(Exception);<br>function GetLocalIpAddress : string;<br> type pu_long = ^u_long; <br> var varTWSAData : TWSAData; <br> varPHostEnt : PHostEnt; <br> varTInAddr : TInAddr; namebuf : Array[0..255] of char; <br> fd : integer; rc : integer; <br>begin <br> result := ""; <br> rc := WSAStartup($101,varTWSAData); <br> if rc <> 0 then raise ESockUtilErr.CreateFmt( "WSA启动错误: %d",[rc] ) <br>else <br>begin <br> gethostname(namebuf,sizeof(namebuf)); <br> varPHostEnt := gethostbyname(namebuf);<br> varTInAddr.S_addr := u_long(pu_long(varPHostEnt^.h_addr_list^)^);<br> result := inet_ntoa(varTInAddr);<br>end;<br> fd := WinSock.Socket( PF_INET, SOCK_STREAM, 0 );<br> if fd = INVALID_SOCKET then raise ESockUtilErr.CreateFmt( "%d %d: 无效 socket",[fd,WSAGetLastError] ); <br> WSACleanup;<br>end;<br>抄的,来骗点分。建议下载:http://www.myf1.net/temp/delphitips.chm <br>