考拉 发表于 2004-5-12 12:43:00

[原创] 我用VB做的计算机网络通讯,winsock控件.

在XP下VB6.0运行通过,有兴趣的看看……
请点这里下载
恩啊……先打开后保存……





[此贴子已经被作者于2004-5-12 20:15:18编辑过]

bruno1122 发表于 2004-5-12 19:17:00

在哪里呀,给我看看

考拉 发表于 2004-5-12 20:15:00

Dim PortNo As Long
Private Sub Command1_Click()
MsgBox "您的IP地址是:" & Winsock1.LocalIP
End Sub
Private Sub Command2_Click()
MsgBox "您的计算机名称是:" & Winsock1.LocalHostName
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Command4_Click()
PortNo = CLng(Text2.Text) - 1
Text4.Text = ""
Command5.Enabled = True
Command4.Enabled = False
If PortNo < 0 Or PortNo > 32767 Then
MsgBox "您的输入错误,端口超过范围"
Command5_Click
Exit Sub
Else
Winsock1.Connect Text1.Text, PortNo
Text4.Text = "开始端口扫描......"
End If
End Sub
Private Sub Command5_Click()
Command5.Enabled = False
Command4.Enabled = True
Winsock1.Close
Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。"
End Sub
Private Sub Command6_Click()
Me.Hide
Form2.Show
End Sub
Private Sub Command7_Click()
FileName = "d:\ipdetail.txt"
Shell "command.com /c ipconfig.exe >" & FileName, vbHide
DoEvents
Do While Trim(Dir(FileName)) = ""
DoEvents
Loop
Dim strstring As String, FileNo
Dim sVar
If Winsock1.LocalPort = 0 Then
strstring = "端口编号未设置!"
Else
strstring = Winsock1.LocalPort
End If
Text5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf
Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf
Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")
FileNo = FreeFile()
Open FileName For Input As #FileNo
While Not EOF(FileNo)
Line Input #FileNo, sVar
Text5.Text = Text5.Text & sVar & vbCrLf
Wend
Close #FileNo
MsgBox Text5.Text
End Sub
Private Sub Command8_Click()
MsgBox "考拉制作!"
End Sub
Private Sub Winsock1_Connect()
Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf
Winsock1.Close
PortNo = PortNo + 1
If PortNo <= CLng(Text3.Text) Then
Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo
Else
Command5_Click
End If
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Winsock1.Close
PortNo = PortNo + 1
If PortNo <= CLng(Text3.Text) Then
Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo
Winsock1.Connect Text1.Text, PortNo
Else
Command5_Click
End If
End Sub

Private Sub Command1_Click()
Winsock1.Protocol = sckUDPProtocol
Winsock1.RemoteHost = Text1.Text
Winsock1.LocalPort = CLng(Text2.Text)
Winsock1.RemotePort = CLng(Text3.Text)
Winsock1.Bind
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
On Error GoTo ConnectError
Winsock1.SendData "Koala:" & Text5.Text
Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text
Text5.Text = ""
Exit Sub
ConnectError:
MsgBox Error_message
End Sub
Private Sub Command3_Click()
Me.Hide
Form1.Show
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command2_Click
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sVar As String
Winsock1.GetData sVar, vbString
Text4.Text = sVar & vbCrLf & Text4.Text
End Sub





[此贴子已经被作者于2004-5-12 20:16:53编辑过]
页: [1]
查看完整版本: [原创]&nbsp;我用VB做的计算机网络通讯,winsock控件.