frmwhois.frm
来自「全面网络扫描器VB源代码 很实用」· FRM 代码 · 共 353 行
FRM
353 行
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmwhois
BackColor = &H00000000&
Caption = "WhoisServers"
ClientHeight = 6600
ClientLeft = 60
ClientTop = 450
ClientWidth = 5310
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 6600
ScaleWidth = 5310
StartUpPosition = 3 '窗口缺省
Begin VB.ListBox List1
Height = 4200
Left = 240
TabIndex = 4
Top = 1080
Width = 4695
End
Begin MSWinsockLib.Winsock Winsock1
Left = 3840
Top = 6240
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.ComboBox Combo1
Height = 315
ItemData = "frmwhois.frx":0000
Left = 2040
List = "frmwhois.frx":0002
TabIndex = 3
Top = 120
Width = 2895
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 3240
TabIndex = 0
Top = 5640
Width = 1695
End
Begin VB.Label Label1
BackColor = &H80000003&
Height = 375
Left = 720
TabIndex = 6
Top = 5640
Width = 2295
End
Begin VB.Label Label4
BackColor = &H80000003&
Caption = "Server"
Height = 255
Left = 1800
TabIndex = 5
Top = 720
Width = 1455
End
Begin VB.Label Label3
BackColor = &H80000003&
Caption = "Country"
Height = 255
Left = 240
TabIndex = 2
Top = 720
Width = 1215
End
Begin VB.Label Label2
BackColor = &H80000003&
Caption = "Country Avaliable"
Height = 375
Left = 360
TabIndex = 1
Top = 120
Width = 1575
End
End
Attribute VB_Name = "frmwhois"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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
On Error Resume Next
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()
On Error Resume Next
'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)
On Error Resume Next
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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?