Results 1 to 2 of 2

Thread: Detecting ISP

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    18

    Question

    I want an application to detect which internet service provider i am using at a particular moment to log on the net(out of the many ISP I use). How can I do that??? Please HELP.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Here you go:
    Code:
    Private Const WSADescription_Len = 256
    Private Const WSASYS_Status_Len = 128
    Private Const WS_VERSION_REQD As Long = &H101
    Private Const IP_SUCCESS As Long = 0
    Private Const SOCKET_ERROR As Long = -1
    Private Const AF_INET = 2
    
    Private Type WSADATA
      wVersion As Integer
      wHighVersion As Integer
      szDescription(0 To WSADescription_Len) As Byte
      szSystemStatus(0 To WSASYS_Status_Len) As Byte
      imaxsockets As Integer
      imaxudp As Integer
      lpszvenderinfo As Long
    End Type
    
    Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal VersionReq As Long, WSADataReturn As WSADATA) As Long
    Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
    Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Long
    Private Declare Function gethostbyaddr Lib "wsock32.dll" (haddr As Long, ByVal hnlen As Long, ByVal addrtype As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (xDest As Any, xSource As Any, ByVal lngBytes As Long)
    Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (lpString As Any) As Long
    
    Public Function SocketsInitialize() As Boolean
        Dim WSAD As WSADATA
       
        SocketsInitialize = WSAStartup(WS_VERSION_REQD, WSAD) = IP_SUCCESS
    End Function
    
    Public Sub SocketsCleanup()
        If WSACleanup() <> 0 Then
            MsgBox "Windows Sockets error occurred in Cleanup.", vbExclamation
        End If
    End Sub
    
    Public Function GetHostNameFromIP(ByVal sAddress As String) As String
        Dim lngHosent As Long
        Dim lngAddress As Long
        Dim lngBytes As Long
       
        If SocketsInitialize() Then
            lngAddress = inet_addr(sAddress)
            If lngAddress <> SOCKET_ERROR Then
                lngHosent = gethostbyaddr(lngAddress, 4, AF_INET)
                If lngHosent <> 0 Then
                    'convert address and
                    'get resolved hostname
                    CopyMemory lngHosent, ByVal lngHosent, 4
                    lngBytes = lstrlen(ByVal lngHosent)
             
                    If lngBytes > 0 Then
                        sAddress = Space$(lngBytes)
                        CopyMemory ByVal sAddress, ByVal lngHosent, lngBytes
                        GetHostNameFromIP = sAddress
                    End If
             
                Else
                    MsgBox "Call to gethostbyaddr failed."
                End If
          
                SocketsCleanup
          
            Else
                MsgBox "String passed is an invalid IP."
            End If
       
        Else
            MsgBox "Sockets failed to initialize."
        End If
    End Function
    
    Private Sub Command1_Click()
        Text1 = GetHostNameFromIP(Text1)
    End Sub
    Type in the IP address in the textbox, press a button and you get the DNS for that IP, i.e vb-world.net etc.

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