|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visual Basic Internet Routines Pure VB: Retrieving WHOIS Data for a Registered Domain |
|
Posted: | Tuesday March 19, 2002 |
Updated: | Monday December 26, 2011 |
Applies to: | VB5, VB6 |
Developed with: | VB6, Windows XP |
OS restrictions: | None |
Author: | VBnet - Randy Birch, MSDN |
Related: |
gethostbyaddr: Obtain Host Name from IP Address |
Prerequisites |
Network or DUN connection, Winsock control. |
|
Here is the minimal code to retrieve WHOIS data from a WHOIS server for a specified domain name. |
BAS Module Code |
None. |
|
Form Code |
To a form add a command button (Command1), two combo boxes (Combo1, Combo2), a label (Label1) and a textbox (Text1) set to multiline with both horizontal and vertical scrollbars. Add a Winsock control (Winsock1) along with the following code: |
|
Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private sWinsockCommand As String Private sDataIn As String Private sDataBuff As String Private Sub Form_Load() Command1.Caption = "Get Whois Info" With Combo1 .AddItem "whois.cira.ca" .AddItem "whois.networksolutions.com" .ListIndex = 0 End With With Combo2 .AddItem "gov.on.ca" .AddItem "sympatico.ca" .AddItem "microsoft.com" .AddItem "goggle.com" .AddItem "mvps.org" .ListIndex = 0 End With End Sub Private Sub Command1_Click() If GetWhosisDomainInfo() Then Label1.Caption = "Retrieving..." End If End Sub Private Sub Form_Unload(Cancel As Integer) If Winsock1.State = sckConnected Then Winsock1.Close End If End Sub Private Function GetWhosisDomainInfo() As Boolean Dim sServer As String sDataIn = "" sDataBuff = "" 'server to connect to sServer = Combo1.List(Combo1.ListIndex) 'the only command required to 'retrieve the whois information is 'to send name of the domain of interest sWinsockCommand = Combo2.List(Combo2.ListIndex) With Winsock1 'avoid error by assuring the 'sockets are closed. .Close .LocalPort = 0 'connect to server .Connect sServer, 43 GetWhosisDomainInfo = .State = sckResolvingHost End With End Function Private Sub Winsock1_Connect() 'if a connection was made, 'pass the command 'to the server If Winsock1.State = sckConnected Then Winsock1.SendData sWinsockCommand & vbCrLf End If End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Winsock1.GetData sDataIn sDataBuff = sDataBuff & sDataIn End Sub Private Sub Winsock1_Close() If Winsock1.State = sckClosing Then Winsock1.Close Text1.Text = "" sDataBuff = Replace(sDataBuff, vbLf, vbCrLf) Text1.Text = sDataBuff End If 'update the label Label1.Caption = "Whois Server:" End Sub |
Comments |
|
|
|
|||||
|
|||||
|
|||||
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |