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 |