//结构对象
global type s_wsadata from structure
unsignedinteger version
unsignedinteger highversion
character discription[257]
character systemstatus[129]
unsignedinteger maxsockets
unsignedinteger maxupddg
string vendorinfo
end type
//函数声明
function int WSAStartup( uint UIVersionRequested, ref s_WSAData lpWSAData ) library "wsock32.dll;ANSI"
function int WSACleanup() library "wsock32.dll;ANSI"
function int WSAGetLastError ( ) library "wsock32.dll;ANSI"
function int gethostname ( ref string name, int namelen ) library "wsock32.dll;ANSI"
function string GetHost(string lpszhost, ref blob lpszaddress ) library "pbws32.dll;ANSI"
//调用string f_get_ip()
s_wsadata l_WSAData
string ls_HostName = space(128)
string ls_IpAddress
int li_version = 257
blob{4} lb_hostaddress
IF wsastartup ( li_version, l_WSAData ) = 0 THEN //运行到这一句报错
IF gethostname ( ls_HostName, len(ls_HostName) ) < 0 THEN
messagebox("GetHostName",WSAGetLastError())
ELSE
GetHost(ls_HostName, lb_HostAddress)
ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,1,1))),"000") + "."
ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,2,1))),"000") + "."
ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,3,1))),"000") + "."
ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,4,1))),"000")
END IF
WSACleanup()
ELSE
messagebox("GetHostName",WSAGetLastError())
END IF
//messagebox('ls_hostname: '+ls_hostname,'ls_ipaddress: '+ls_ipaddress)
return ls_ipaddress
------解决思路----------------------
我使用GETIP60.dll
宣告
Function uLong GetHostIpList(ref string hostAddressip) Library "GetIP60.dll" Alias For "GetHostIpList;ansi"
Function uLong Gethost(ref string hostname) Library "GetIP60.dll" Alias For "Gethost;ansi"
使用
string ls_HostIP = Space(128)
GetHostIpList(ls_HostIP)
------解决思路----------------------
收藏