Results 1 to 4 of 4

Thread: How to get ip out of text ip?(cant explain?)

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    How to get ip out of text ip?(cant explain?)

    Some ips are like yay.no-ip.org, and i need to be able to find what the real ip is from it ( i know its an api, just which one!) thanks

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to get ip out of text ip?(cant explain?)

    There might be something here that could help.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to get ip out of text ip?(cant explain?)

    Or this one.

  4. #4
    Fanatic Member
    Join Date
    Jan 2005
    Location
    In front of this pc.
    Posts
    580

    Re: How to get ip out of text ip?(cant explain?)

    I havn't been up long so maybe my brain is still muddled and I'm missing something here but...

    IPAs are numeric by definition...URLs are the easily remembered alpha-numeric designators (yahoo.com for example). If you have a URL and need the corresponding IPA try this code in a module calling vbIPFromHostName.

    VB Code:
    1. Option Explicit
    2.  
    3. Public Type hostent
    4.     hName     As Long
    5.     hAliases  As Long
    6.     hAddrType As Integer
    7.     hLength   As Integer
    8.     hAddrList As Long
    9. End Type
    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 MIN_SOCKETS_REQD As Long = 1
    14. Public Const MAX_WSADescription = 256
    15. Public Const ERROR_SUCCESS = 0
    16. Public Const MAX_WSASYSStatus = 128
    17. Public Type WSAData
    18.     wVersion As Integer
    19.     wHighVersion As Integer
    20.     szDescription(0 To MAX_WSADescription) As Byte
    21.     szSystemStatus(0 To MAX_WSASYSStatus) As Byte
    22.     wMaxSockets As Integer
    23.     wMaxUDPDG As Integer
    24.     dwVendorInfo As Long
    25. End Type
    26.  
    27. Public Const INADDR_NONE = &HFFFF
    28. Declare Function WSAStartup Lib "WSOCK32" _
    29.     (ByVal wVersionRequired As Long, lpWSADATA As WSAData) As Long
    30. Public Declare Function WSACleanup Lib "WSOCK32" () As Long
    31. Public Declare Function inet_addr Lib "ws2_32.dll" (ByVal cp As String) As Long
    32. Public Declare Function gethostbyname Lib "ws2_32.dll" _
    33.     (ByVal host_name As String) As Long
    34. Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _
    35.     (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
    36.  
    37. Public Function vbIPFromHostName(ByVal strHostName As String) As String
    38.     Dim udtHost                As hostent
    39.     Dim lngIPAddress           As Long
    40.     Dim lngPointer             As Long
    41.     Dim bytIPAddress(0 To 3)   As Byte
    42.     Dim strBuffer              As String
    43.     Dim i                      As Long
    44.    
    45.     If SocketsInitialize = False Then
    46.         vbIPFromHostName = "init failure"
    47.         Exit Function
    48.     End If
    49.    
    50.     lngIPAddress = vbInetAddr(strHostName)
    51.     If (lngIPAddress <> INADDR_NONE) Then
    52.         vbIPFromHostName = strHostName
    53.         Exit Function
    54.     End If
    55.    
    56.     lngPointer = gethostbyname(strHostName)
    57.     If (lngPointer) Then
    58.         Call CopyMemory(udtHost, ByVal lngPointer, LenB(udtHost))
    59.         Call CopyMemory(lngPointer, ByVal udtHost.hAddrList, udtHost.hLength)
    60.         Call CopyMemory(bytIPAddress(0), ByVal lngPointer, udtHost.hLength)
    61.         For i = 0 To 3
    62.             strBuffer = strBuffer & CStr(bytIPAddress(i)) & "."
    63.         Next i
    64.         vbIPFromHostName = Mid$(strBuffer, 1, Len(strBuffer) - 1)
    65.     Else
    66.         vbIPFromHostName = "Lookup Failed!"
    67.     End If
    68.     SocketsCleanup
    69. End Function
    70.  
    71. Public Function vbInetAddr(ByVal strIPAddress As String) As Long
    72.     ' Convert a dotted IP address into a network byte integer.
    73.     vbInetAddr = inet_addr(strIPAddress)
    74. End Function
    75.  
    76. Public Sub SocketsCleanup()
    77.     If WSACleanup() <> ERROR_SUCCESS Then
    78.         MsgBox "Socket error occurred in Cleanup."
    79.     End If
    80. End Sub
    81.  
    82. Public Function SocketsInitialize() As Boolean
    83.     Dim WSAD As WSAData
    84.     Dim sLoByte As String
    85.     Dim sHiByte As String
    86.     If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
    87.         MsgBox "The 32-bit Windows Socket is not responding."
    88.         SocketsInitialize = False
    89.         Exit Function
    90.     End If
    91.     If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
    92.         MsgBox "This application requires a minimum of " & CStr(MIN_SOCKETS_REQD) _
    93.             & " supported sockets."
    94.         SocketsInitialize = False
    95.         Exit Function
    96.     End If
    97.     If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or (LoByte(WSAD.wVersion) = _
    98.       WS_VERSION_MAJOR And HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
    99.         sHiByte = CStr(HiByte(WSAD.wVersion))
    100.         sLoByte = CStr(LoByte(WSAD.wVersion))
    101.         MsgBox "Sockets version " & sLoByte & "." & sHiByte & _
    102.             " is not supported by 32-bit Windows Sockets."
    103.         SocketsInitialize = False
    104.         Exit Function
    105.     End If
    106.     'must be OK, so lets do it
    107.     SocketsInitialize = True
    108. End Function
    109.  
    110. Public Function HiByte(ByVal wParam As Integer)
    111.     HiByte = wParam \ &H100 And &HFF&
    112. End Function
    113.  
    114. Public Function LoByte(ByVal wParam As Integer)
    115.     LoByte = wParam And &HFF&
    116. End Function

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