* 堕天使 * 于 2001.9.25 http://NetIs.126.com (转载请标明出处)
===========
** 本文将介绍VB下利用WinSock控件,编写简单的网络应用程序 **
** 写给所有对网络编程有兴趣的初学者!**
================================== 这是一个简单的“端口扫描的程序”的源代码 一. 控件说明: 窗 口: frmScan ** frmScan 中的控件 **
* TextBox :
txtIP (对方的IP)
txtLowerBound (起始端口)
txtUpperBound (结束端口)
txtMaxConnections (最多使用的连接数量)
lstOpenPorts (列出开放的端口)
* CommandButton :
cmdScan (开始扫描)
cmdStop (结束扫描)
cmdClearList (清除开放端口的列表)
* Winsock:
wskSocket (TCP协议)
* Timer:
timTimer (超时设置)
********************** 二. 程序源代码:
========================================= Option Explicit
Dim lngNextPort As Long Private Sub cmdClearList_Click()
Me.lstOpenPorts.Clear
End Sub Private Sub cmdScan_Click()
Dim intI As Integer
lngNextPort = Val(Me.txtLowerBound)
For intI = 1 To Val(Me.txtMaxConnections)
Load Me.wskSocket(intI)
lngNextPort = lngNextPort + 1
Me.wskSocket(intI).Connect Me.txtIP, lngNextPort
Next intI
End Sub Private Sub cmdStop_Click()
Dim intI As Integer
For intI = 1 To Val(Me.txtMaxConnections)
Me.wskSocket(intI).Close
Unload Me.wskSocket(intI)
Next intI
End Sub Private Sub timTimer_Timer()
Me.sbMain.Panels(1).Text = "Current Port: " + Str(lngNextPort)
End Sub Private Sub wskSocket_Connect(Index As Integer)
Me.lstOpenPorts.AddItem "Port: " + Str(Me.wskSocket(Index).RemotePort)
Try_Next_Port (Index)
End Sub Private Sub wskSocket_Error(Index As Integer, 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)
Try_Next_Port (Index)
End Sub Private Sub Try_Next_Port(Index As Integer)
Me.wskSocket(Index).Close
If lngNextPort < Val(Me.txtUpperBound) Then
Me.wskSocket(Index).Connect , lngNextPort
lngNextPort = lngNextPort + 1
Else
Unload Me.wskSocket(Index)
End If
End Sub ========================================= 代码其实很简单,相信大家很容易就看懂了!
最近没什么时间,所以上次的UPD协议迟了两天才写出来。
不过我还是会陆续将一些程序源代码帖出来以供大家参考。 --------------------------------------------------
接下来我将帖出一些程序的源代码供大家参考!
如果你感兴趣的请到 http://NetIs.126.com
版权归 Cninf.com 所有,转载请注明出处,谢谢!
被放逐的天使 ......
....................................................转贴.........................................