Results 1 to 3 of 3

Thread: Ip

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    Canada
    Posts
    202

    Ip

    How do I get my IP address?

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    You can use the API
    VB Code:
    1. 'In a form
    2. Private Sub Form_Load()
    3.     'KPD-Team 1999
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.     'E-Mail: [email][email protected][/email]
    6.     MsgBox "IP-address: " + GetIPAddress
    7. End Sub
    8. 'In a module
    9. Public Const MIN_SOCKETS_REQD As Long = 1
    10. Public Const WS_VERSION_REQD As Long = &H101
    11. Public Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD \ &H100 And &HFF&
    12. Public Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&
    13. Public Const SOCKET_ERROR As Long = -1
    14. Public Const WSADESCRIPTION_LEN = 257
    15. Public Const WSASYS_STATUS_LEN = 129
    16. Public Const MAX_WSADescription = 256
    17. Public Const MAX_WSASYSStatus = 128
    18. Public Type WSAData
    19.     wVersion As Integer
    20.     wHighVersion As Integer
    21.     szDescription(0 To MAX_WSADescription) As Byte
    22.     szSystemStatus(0 To MAX_WSASYSStatus) As Byte
    23.     wMaxSockets As Integer
    24.     wMaxUDPDG As Integer
    25.     dwVendorInfo As Long
    26. End Type
    27. Type WSADataInfo
    28.     wVersion As Integer
    29.     wHighVersion As Integer
    30.     szDescription As String * WSADESCRIPTION_LEN
    31.     szSystemStatus As String * WSASYS_STATUS_LEN
    32.     iMaxSockets As Integer
    33.     iMaxUdpDg As Integer
    34.     lpVendorInfo As String
    35. End Type
    36. Public Type HOSTENT
    37.     hName As Long
    38.     hAliases As Long
    39.     hAddrType As Integer
    40.     hLen As Integer
    41.     hAddrList As Long
    42. End Type
    43. Declare Function WSAStartupInfo Lib "WSOCK32" Alias "WSAStartup" (ByVal wVersionRequested As Integer, lpWSADATA As WSADataInfo) As Long
    44. Declare Function WSACleanup Lib "WSOCK32" () As Long
    45. Declare Function WSAGetLastError Lib "WSOCK32" () As Long
    46. Declare Function WSAStartup Lib "WSOCK32" (ByVal wVersionRequired As Long, lpWSADATA As WSAData) As Long
    47. Declare Function gethostname Lib "WSOCK32" (ByVal szHost As String, ByVal dwHostLen As Long) As Long
    48. Declare Function gethostbyname Lib "WSOCK32" (ByVal szHost As String) As Long
    49. Declare Sub CopyMemoryIP Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
    50. Public Function GetIPAddress() As String
    51.     Dim sHostName As String * 256
    52.     Dim lpHost As Long
    53.     Dim HOST As HOSTENT
    54.     Dim dwIPAddr As Long
    55.     Dim tmpIPAddr() As Byte
    56.     Dim I As Integer
    57.     Dim sIPAddr As String
    58.     If Not SocketsInitialize() Then
    59.         GetIPAddress = ""
    60.         Exit Function
    61.     End If
    62.     If gethostname(sHostName, 256) = SOCKET_ERROR Then
    63.         GetIPAddress = ""
    64.         MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & " has occurred. Unable to successfully get Host Name."
    65.         SocketsCleanup
    66.         Exit Function
    67.     End If
    68.     sHostName = Trim$(sHostName)
    69.     lpHost = gethostbyname(sHostName)
    70.     If lpHost = 0 Then
    71.         GetIPAddress = ""
    72.         MsgBox "Windows Sockets are not responding. " & "Unable to successfully get Host Name."
    73.         SocketsCleanup
    74.         Exit Function
    75.     End If
    76.     CopyMemoryIP HOST, lpHost, Len(HOST)
    77.     CopyMemoryIP dwIPAddr, HOST.hAddrList, 4
    78.     ReDim tmpIPAddr(1 To HOST.hLen)
    79.     CopyMemoryIP tmpIPAddr(1), dwIPAddr, HOST.hLen
    80.     For I = 1 To HOST.hLen
    81.         sIPAddr = sIPAddr & tmpIPAddr(I) & "."
    82.     Next
    83.     GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
    84.     SocketsCleanup
    85. End Function
    86. Public Function GetIPHostName() As String
    87.     Dim sHostName As String * 256
    88.     If Not SocketsInitialize() Then
    89.         GetIPHostName = ""
    90.         Exit Function
    91.     End If
    92.     If gethostname(sHostName, 256) = SOCKET_ERROR Then
    93.         GetIPHostName = ""
    94.         MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & " has occurred. Unable to successfully get Host Name."
    95.         SocketsCleanup
    96.         Exit Function
    97.     End If
    98.     GetIPHostName = Left$(sHostName, InStr(sHostName, Chr(0)) - 1)
    99.     SocketsCleanup
    100. End Function
    101. Public Function HiByte(ByVal wParam As Integer)
    102.     HiByte = wParam \ &H100 And &HFF&
    103. End Function
    104. Public Function LoByte(ByVal wParam As Integer)
    105.     LoByte = wParam And &HFF&
    106. End Function
    107. Public Sub SocketsCleanup()
    108.     If WSACleanup() <> ERROR_SUCCESS Then
    109.         MsgBox "Socket error occurred in Cleanup."
    110.     End If
    111. End Sub
    112. Public Function SocketsInitialize() As Boolean
    113.     Dim WSAD As WSAData
    114.     Dim sLoByte As String
    115.     Dim sHiByte As String
    116.     If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
    117.         MsgBox "The 32-bit Windows Socket is not responding."
    118.         SocketsInitialize = False
    119.         Exit Function
    120.     End If
    121.     If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
    122.         MsgBox "This application requires a minimum of " & CStr(MIN_SOCKETS_REQD) & " supported sockets."
    123.         SocketsInitialize = False
    124.         Exit Function
    125.     End If
    126.     If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
    127.         sHiByte = CStr(HiByte(WSAD.wVersion))
    128.         sLoByte = CStr(LoByte(WSAD.wVersion))
    129.         MsgBox "Sockets version " & sLoByte & "." & sHiByte & " is not supported by 32-bit Windows Sockets."
    130.         SocketsInitialize = False
    131.         Exit Function
    132.     End If
    133.     'must be OK, so lets do it
    134.     SocketsInitialize = True
    135. End Function

    or the WinSock Control

    ipaddress = WinSock1.LocalIP
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

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