Results 1 to 3 of 3

Thread: IP's and things

  1. #1

    Thread Starter
    Member SapphireGreen's Avatar
    Join Date
    Sep 2001
    Location
    I do not actually exist
    Posts
    45

    IP's and things

    Does anyone know how to get the IP of a user with API's?

    I've tried, but I can't find any information.
    On Error Give Up

    Mind over matter. Then if it doesn't matter, you lose your mind.

  2. #2
    Matthew Gates
    Guest
    Try this:


    VB Code:
    1. Public Const WS_VERSION_REQD = &H101
    2. Public Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100  And &HFF&
    3. Public Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
    4. Public Const MIN_SOCKETS_REQD = 1
    5. Public Const SOCKET_ERROR = -1
    6. Public Const WSADescription_Len = 256
    7. Public Const WSASYS_Status_Len = 128
    8.  
    9. Public Type HOSTENT
    10.     hName As Long
    11.     hAliases As Long
    12.     hAddrType As Integer
    13.     hLength As Integer
    14.     hAddrList As Long
    15. End Type
    16.  
    17. Public Type WSADATA
    18.     wversion As Integer
    19.     wHighVersion As Integer
    20.     szDescription(0 To WSADescription_Len) As Byte
    21.     szSystemStatus(0 To WSASYS_Status_Len) As Byte
    22.     iMaxSockets As Integer
    23.     iMaxUdpDg As Integer
    24.     lpszVendorInfo As Long
    25. End Type
    26.  
    27. Public Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
    28. Public Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired&, lpWSAData As WSADATA) As Long
    29. Public Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
    30. Public Declare Function gethostname Lib "WSOCK32.DLL" (ByVal hostname$, ByVal HostLen As Long) As Long
    31. Public Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal hostname$) As Long
    32. Public Declare Sub RtlMoveMemory Lib "kernel32" (hpvDest As Any, ByVal hpvSource&, ByVal cbCopy&)
    33.  
    34. Function hibyte(ByVal wParam As Integer)
    35.     hibyte = wParam \ &H100  And &HFF&
    36. End Function
    37.  
    38.  
    39. Function lobyte(ByVal wParam As Integer)
    40.     lobyte = wParam And &HFF&
    41. End Function
    42.  
    43.  
    44. Sub SocketsInitialize()
    45.     Dim WSAD As WSADATA
    46.     Dim iReturn As Integer
    47.     Dim sLowByte As String, sHighByte As String, sMsg As String
    48.     iReturn = WSAStartup(WS_VERSION_REQD, WSAD)
    49.  
    50.  
    51.     If iReturn <> 0 Then
    52.         MsgBox "Winsock.dll Error."
    53.         End
    54.     End If
    55.     If lobyte(WSAD.wversion) < WS_VERSION_MAJOR Or (lobyte(WSAD.wversion) = _
    56.         WS_VERSION_MAJOR And hibyte(WSAD.wversion) < WS_VERSION_MINOR) Then
    57.         sHighByte = Trim$(Str$(hibyte(WSAD.wversion)))
    58.         sLowByte = Trim$(Str$(lobyte(WSAD.wversion)))
    59.         sMsg = "Windows Sockets version " & sLowByte & "." & sHighByte
    60.         'sMsg = sMsg & " winsock.dll tarafindan desteklenmiyor. "
    61.         MsgBox sMsg
    62.         End
    63.     End If
    64.  
    65. End Sub
    66.  
    67. Public Function CurrentIP(ReturnExternalIP As Boolean)
    68.     Dim hostname As String * 256
    69.     Dim hostent_addr As Long
    70.     Dim host As HOSTENT
    71.     Dim hostip_addr As Long
    72.     Dim temp_ip_address() As Byte
    73.     Dim i As Integer
    74.     Dim ip_address As String
    75.     Dim IP As String
    76.  
    77.     If gethostname(hostname, 256) = SOCKET_ERROR Then
    78.         MsgBox "Windows Socket Error " & Str(WSAGetLastError())
    79.         Exit Function
    80.     Else
    81.         hostname = Trim$(hostname)
    82.     End If
    83.     hostent_addr = gethostbyname(hostname)
    84.  
    85.  
    86.     If hostent_addr = 0 Then
    87.         MsgBox "Winsock.dll error."
    88.         Exit Function
    89.     End If
    90.     RtlMoveMemory host, hostent_addr, LenB(host)
    91.     RtlMoveMemory hostip_addr, host.hAddrList, 4
    92.    
    93.     Do
    94.         ReDim temp_ip_address(1 To host.hLength)
    95.         RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength
    96.  
    97.  
    98.         For i = 1 To host.hLength
    99.             ip_address = ip_address & temp_ip_address(i) & "."
    100.         Next
    101.         ip_address = Mid$(ip_address, 1, Len(ip_address) - 1)
    102.        
    103.         Internal = TheIP        ' Send ONLY the External IP to the CurrentIP Function
    104.         EXTERNAL = ip_address   ' Send the External IP to the  function parameter External
    105.         TheIP = ip_address      ' Send LAN IP to the function para Internal
    106.      
    107.         ip_address = ""
    108.         host.hAddrList = host.hAddrList + LenB(host.hAddrList)
    109.         RtlMoveMemory hostip_addr, host.hAddrList, 4
    110.     Loop While (hostip_addr <> 0)
    111.    
    112.    
    113. If ReturnExternalIP = True Then
    114.     CurrentIP = EXTERNAL
    115. Else
    116.     CurrentIP = Internal
    117. End If
    118. End Function
    119.  
    120. Sub SocketsCleanup()
    121.     Dim lReturn As Long
    122.     lReturn = WSACleanup()
    123.  
    124.  
    125.     If lReturn <> 0 Then
    126.         MsgBox "Socket Error " & Trim$(Str$(lReturn)) & " occurred In Cleanup "
    127.         End
    128.     End If
    129. End Sub
    130.  
    131.  
    132. [b][u]Usage[/u][/b]
    133.  
    134.  
    135. Private Sub Command1_Click()
    136.     SocketsInitialize
    137.     Msgbox CurrentIP(True)
    138. End Sub

  3. #3
    Si_the_geek
    Guest
    I dont think you can, but you can use "gethostbyname" to get the IP of a machine from it's name.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width