VB Socket获取主机名和IP地址
代码说明:
VB Socket获取主机名和IP地址,获取主机名是使用了VB中的GetComputerName直接得到,然后对Socket初始化,使用gethostbyname取得主机地址,再获取到IP后进行转化为标准的IP格式。转换过程如下: RtlMoveMemory host, hostent_addr, LenB(host) RtlMoveMemory hostip_addr, host.hAddrList, 4 ReDim temp_ip_address(1 To host.hLength) RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength For i = 1 To host.hLength ip_address = ip_address & temp_ip_address(i) & "." Next i ip_address = Mid$(ip_address, 1, Len(ip_address) - 1) MsgBox "IP:" + ip_address
下载说明:请别用迅雷下载,失败请重下,重下不扣分!