Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi friends, I am trying to make

Status
Not open for further replies.

MakeItSo

Programmer
Oct 21, 2003
3,316
DE
Hi friends,

I am trying to make my own little WhoIs lookup application. I understand it would probably be easier to use MSHTML, pass the IP to WhoIs and query the results page.
That would be enough to resolve the hosting country and net name.
However, I would also like to read the abuse email addresses. Unfortunately, these are not displayed in plain text (at domaintools.com). Plus: have a look at the source code - it seems that horrible layout coding is a precondition for those sites! [sadeyes]

What I've got so far is:
a) An API call to resolve the IP into the hostname:
Code:
Public Function GetHostNameFromIP(ByVal sIPAddress As String) As String
    
    Dim ptrHosent As Long
    Dim hAddress As Long
    Dim sHost As String
    Dim nBytes As Long
    
    'try to open the socket
    If InitializeSocket() = True Then
    
        'convert string address to long datatype
        hAddress = apiInetAddr(sIPAddress)
        
        'check if an error ocucred
        If hAddress <> SOCKET_ERROR Then
            
            'obtain a pointer to the HOSTENT structure
            'that contains the name and address
            'corresponding to the given network address.
            ptrHosent = apiGetHostByAddr(hAddress, 4, AF_INET)
            
            If ptrHosent <> 0 Then
                
                'convert address and
                'get resolved hostname

                apiCopyMemory ptrHosent, ByVal ptrHosent, 4
                
                nBytes = apiStrLen(ByVal ptrHosent)
                
                If nBytes > 0 Then
                    'fill the IP address buffer
                    sHost = Space$(nBytes)
                    
                    apiCopyMemory ByVal sHost, ByVal ptrHosent, nBytes
                    GetHostNameFromIP = sHost
                End If
            Else
                MsgBox "Call to gethostbyaddr failed."
            End If
            'close the socket
            CloseSocket
        Else
            MsgBox "Invalid IP address"
        End If
    Else
        MsgBox "Failed to open Socket"
    End If
End Function
Full code credits to developerfusion.

I also found a simple VB6 WhoIs online, which unfortunately does not seem to work:
Code:
Private Function whois(domain As String)
   Dim sServer As String
   sDataIn = ""
   sDataBuff = ""
   If Right(Text1.Text, 4) = ".com" Then sServer = "rs.internic.net"
   If Right(Text1.Text, 4) = ".net" Then sServer = "rs.internic.net"
   If Right(Text1.Text, 4) = ".org" Then sServer = "whois.publicinterestregistry.net"
   If Right(Text1.Text, 4) = ".edu" Then sServer = "whois.educause.net"
   If Right(Text1.Text, 4) = ".gov" Then sServer = "whois.nic.gov"
   If Right(Text1.Text, 5) = ".info" Then sServer = "whois.afilias.info"
   If Right(Text1.Text, 3) = ".ru" Then sServer = "whois.ripn.ru"
   sWinsockCommand = domain
   With Winsock1
      .Close
      .LocalPort = 0
      .Connect sServer, 43
      [b]whois = .State = sckResolvingHost[/b]
   End With
End Function
I bolded that part because the control stays in State 6 (connecting). [sadeyes]

Anyone got any idea that might help me?

Thanks & regards,
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
The example code probably hangs because of obsolete WHJOIS server names used there. These change over time and you almost need to query whois.iana.org to find out who handles a given top-level domain, and then requery there, etc. following the redirects.

For example currently .com, .net, and .edu seem to be handled by whois.verisign-grs.com from what I can see.

Also note that almost all of the servers warn you that these services are not for automated use.

Example:
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability. VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.

I'd say give it up and move on to a more useful project.
 
Thanks for that info on the Terms of Use - should have checked that before. [sad]
Anyway: this project is not urgent and it is but a first test, yet I would not call it "not useful enough" or anything like that.
I might have to come up with some alternative and resolving the host name from the IP already works relatively well without the need for a WhoIs site.
There must be legal ways to getting more than just the host name.


“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top