'获取本机IP
'J        =0  第1张网卡
'     =1  第2张网卡
'     ....   第n张网卡
#include Once "win/winsock2.bi"
Function GetNativeIP(J As Long = 0) As String '获取本机IP
   '//1.初始化wsa
   Dim wsaData As WSAData
   If WSAStartup(MAKEWORD(1, 1), @wsaData) Then
      '"初始化 WinSock 失败！！"
   Else
      '//2.获取主机名
      Dim hostname As ZString * 256
      If gethostname(@hostname, SizeOf(hostname)) = SOCKET_ERROR Then
         '"失败！！"
      Else
         'Print hostname
         Dim pHost As hostent Ptr
         Dim ia As in_addr
         Dim i As Long
         pHost = gethostbyname(@hostname)
         Do
            If pHost->h_addr_list[i] = 0 Then Exit Do
            memcpy(@ia, pHost->h_addr_list[i], pHost->h_length)
            Function = *inet_ntoa(ia)
            If i = j Then Exit Do
            i += 1
         Loop
      End If
   End If
   WSACleanup
   
End Function