|
|
![]() |
|
||
|
|
|||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visual Basic Internet Routines Pure VB: Obtaining a Listing of WHOIS Servers |
|
| 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 gethostbyname: Resolve Host Name to IP Address IcmpSendEcho: Ping a Machine by IP Address IcmpSendEcho: Ping a Machine by Host Name Pure VB: Obtaining a Listing of WHOIS Servers Pure VB: Retrieving WHOIS Data for a Registered Domain |
| Prerequisites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Network or DUN connection, Winsock control. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In
order to connect a host to the Internet, you must register a domain name
with the InterNIC. The InterNIC is responsible for registering top second
level domains EDU, ORG, GOV, COM, and NET. WHOIS is a service that provides information on these second-level domains including contact email addresses, postal addresses and telephone numbers of those who have registered the domain. WHOIS can also help determine whether a domain name is already in use which can be helpful for new site administrators. The information contained in the InterNIC database can be especially valuable if there is a problem with internetworking between two domains. For example, WHOIS can help determine who to contact if there is a problem with a domain that can not be resolved via email by providing the name and phone number of the administrator at a destination host. This page shows how, using the VB Winsock control, you can connect to a WHOIS server to request a list of WHOIS servers. The data returned is parsed to extract the server name and country of the server, then used to populate a listbox reflecting the servers for the country selected in the combo. Provided for additional information is the following listing of common ports: Well-Known Ports
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BAS Module Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| None. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Form Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| To a form add a command button (Command1), a combo (Combo1), a listbox (List1), and a label (Label1). 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 'command string since Winsock can't accept parameters
Private sDataIn As String 'in: data blocks received by Winsock
Private sDataBuff As String 'buffer of all data blocks
Private Const LB_SETTABSTOPS As Long = &H192
Private Const CB_FINDSTRING As Long = &H14C
Private Const CB_FINDSTRINGEXACT As Long = &H158
Private Type WhoisServers
country As String
server As String
End Type
Private whois() As WhoisServers 'UDT holding the servers and countries
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Sub Form_Load()
ReDim TabArray(0 To 0) As Long
TabArray(0) = 38
'set the list tabstops
Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&)
Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 1&, TabArray(0))
Command1.Caption = "Get Whois Servers"
End Sub
Private Sub Command1_Click()
If GetWhosisServerList() 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 FindStringInCombo(ByVal sItem As String) As Boolean
'if the combo already contains
'the string specified as sItem,
'return True.
FindStringInCombo = SendMessage(Combo1.hwnd, _
CB_FINDSTRINGEXACT, _
-1, _
ByVal sItem) <> -1
End Function
Private Function GetWhosisServerList() As Boolean
List1.Clear
'the only command required to
'retrieve the server list is
'to send "whois-servers"
sWinsockCommand = "whois-servers" & vbCrLf
With Winsock1
.LocalPort = 0
'avoid error by assuring the
'sockets are closed.
.Close
'connect to a whois data sever
'using port 43, defined
'in Windows' Services file as:
' nicname 43/tcp whois
.Connect "sipb.mit.edu", 43
GetWhosisServerList = .State = sckResolvingHost
End With
End Function
Private Sub Combo1_Click()
Dim cnt As Long
If Combo1.ListIndex > -1 Then
List1.Clear
For cnt = 0 To UBound(whois) - 1
'if "All Servers", just list them
If Combo1.ListIndex = 0 Then
List1.AddItem whois(cnt).country & _
vbTab & whois(cnt).server
Else
'if the .country string
'matches the selected list
'item, add it to the list
If whois(cnt).country = Combo1.List(Combo1.ListIndex) Then
List1.AddItem whois(cnt).country & _
vbTab & whois(cnt).server
End If 'If whois(cnt).country
End If 'If Combo1.ListIndex
Next cnt
End If 'If Combo1.ListIndex
End Sub
Private Sub Winsock1_Connect()
'if a connection was made,
'pass the retrive command
'to the server
If Winsock1.State = sckConnected Then
Winsock1.SendData sWinsockCommand
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData sDataIn
sDataBuff = sDataBuff & sDataIn
End Sub
Private Sub Winsock1_Close()
Dim buff() As String 'buffer for Split()
Dim country As String 'the country
Dim pos As String 'instr() counter
Dim x As Long 'array counter
Dim cnt As Long 'item counter
If Winsock1.State = sckClosing Then
'assure closed
Winsock1.Close
List1.Clear
Combo1.Clear
Combo1.AddItem "All servers"
'initialize the array to 500 members
ReDim whois(0 To 500) As WhoisServers
cnt = 0
'Split out the returned info using
'VB6's Split command. Users of
'VB4-32 or VB5 will need to write
'code to replicate the Split method.
'
'Note that although the server used
'in this demo (sipb.mit.edu) returns
'text data containing the CrLf sequence
'used in Split() below, some servers
'return data in Unix-format, thereby
'requiring a set of Replace() calls to
'change the vbLf in the Unix files
'to vbCrLf's.
buff = Split(sDataBuff, vbCrLf)
For x = 0 To UBound(buff) - 1
'the server data returned is
'in the format:
'whois.alabanza.com Alabanza, Inc C=US
'where the first portion is
'the server, followed by the
'name of the provider, and the
'country. Therefore to populate
'the whois array, the constituent
'members need to be stripped out.
If Left$(buff(x), 1) <> ";" And _
InStr(buff(x), ".") Then
'locate the start of the country
pos = InStr(buff(x), "C=")
'and if found, extract the country code
If pos Then
country = Mid$(buff(x), pos + 2, Len(buff(x)))
End If
'if the array will exceed 500 items,
'add more
If (cnt + 1) Mod 500 = 0 Then
ReDim Preserve whois(0 To cnt * 2) As WhoisServers
End If
'Combo1 lists the countries to
'display of servers for specific
'countries, if desired. To prevent
'multiple entries call a method
'that determines if the combo
'currently contains the country,
'and only add it if it is not
'already in the combo
If FindStringInCombo(country) = False Then
Combo1.AddItem country
End If
'add the country and server
'data to the whois type
With whois(cnt)
.country = country
.server = Left$(buff(x), InStr(buff(x), Chr$(32)))
End With
'increment counter
cnt = cnt + 1
End If
Next x
'since the whois array will contain
'more members than actually used,
'trim off unused elements from the array
ReDim Preserve whois(0 To cnt) As WhoisServers
End If
'cause the combo click event
'to fire to load the listbox
'and update the label
Combo1.ListIndex = 0
Label1.Caption = "Countries Available:"
End Sub |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comments | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|||||
|
|||||
|
|
|||||
|
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |
![]() |