|
3楼
楼主 |
发表于 2004-5-12 20:15:00
|
只看该作者
Dim PortNo As Long
$ {# {& B+ l, _4 L0 C! [7 x$ \Private Sub Command1_Click()
3 |5 k9 Z$ e* k6 V5 Z- rMsgBox "您的IP地址是:" & Winsock1.LocalIP
: f6 Z$ I! c( {0 F, E9 l1 L4 N/ ]2 \End Sub; H6 `8 R! J* o5 |" } F
Private Sub Command2_Click()
4 X7 f }5 Z7 s! c! r5 U" rMsgBox "您的计算机名称是:" & Winsock1.LocalHostName: c: i) [* L# \ t m
End Sub
! g! S8 q6 v" }Private Sub Command3_Click()
' w$ E; N- V, YEnd' @ v5 q, A& t- M
End Sub
" r: E" ]- ^$ `& J2 vPrivate Sub Command4_Click()
, p3 O& Y8 K& E, z1 J- m1 A- q: ~' cPortNo = CLng(Text2.Text) - 1$ r' R4 |* V' Q' R/ X: }& n& ~5 J
Text4.Text = ""
9 z8 [1 @: g4 `% SCommand5.Enabled = True0 L+ f$ `, a- ?: x& E
Command4.Enabled = False, M/ b% m2 O. G$ r6 p* n: C1 M
If PortNo < 0 Or PortNo > 32767 Then
# H8 @, R, x; i- _$ p- RMsgBox "您的输入错误,端口超过范围"/ f1 r" g1 `+ s( V3 }5 G) c
Command5_Click. G2 Z; a# d$ C( G. Y
Exit Sub
6 X( A! a5 o8 FElse* n0 d" `* i( C% O
Winsock1.Connect Text1.Text, PortNo
2 z: k4 r8 m! r% ?6 f9 KText4.Text = "开始端口扫描......"/ R& q: a7 _7 t A* ~3 M
End If# P$ B7 d% Z8 s% Q8 L
End Sub0 B2 y) g! _6 }3 a! A. e% s
Private Sub Command5_Click()
% d4 m# G5 {+ c' _- y9 @Command5.Enabled = False3 O9 L& v' {- n7 O" T
Command4.Enabled = True5 q# Z+ M" E9 g- y( n
Winsock1.Close* Q( Q4 G# Q/ E
Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。"# }) t( o* h7 [) g0 K1 y
End Sub& q" W! U% L& S/ R3 Z
Private Sub Command6_Click()# z9 W" O9 _6 y+ F/ o7 ]$ p
Me.Hide
h& M+ o! B3 ]& uForm2.Show
: H6 y+ U6 n0 S+ n% tEnd Sub
! c. a5 t% H; h5 r. pPrivate Sub Command7_Click()
5 X N8 f$ O" a, R8 PFileName = "d:\ipdetail.txt"
& M' W# s9 U, T, M! KShell "command.com /c ipconfig.exe >" & FileName, vbHide7 R8 `$ \4 B9 r& F" B% Q9 _
DoEvents4 s# D) u' X9 u$ R
Do While Trim(Dir(FileName)) = ""
( V) B p! Y S* C: BDoEvents
+ q9 N5 F/ T- |0 {$ y' lLoop1 e! [$ Q3 t+ m$ O5 D' W
Dim strstring As String, FileNo
, w: Z# D, n: j% n7 Q. A7 CDim sVar
# b2 z' D+ v m! q2 jIf Winsock1.LocalPort = 0 Then" ]3 E( k1 k1 S6 d3 N z
strstring = "端口编号未设置!"; Z7 ] U7 e2 ?- n5 ?9 ~
Else; i) m8 ?8 O$ f0 y3 W
strstring = Winsock1.LocalPort
: N2 ^& g" i3 B _1 tEnd If
0 ]1 F% R, |$ k! T' M/ IText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf
6 S+ d, c; c/ X7 ]1 d# {Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf+ `/ p8 D: R" v. Z$ F6 v
Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")) |8 k6 x, {* W& v& E( Y( H
FileNo = FreeFile()
$ j* ^- [" g+ x; ?1 |$ POpen FileName For Input As #FileNo0 P8 j: U! I" q' L: |3 @( Q( o
While Not EOF(FileNo)6 i4 [' n5 P* j
Line Input #FileNo, sVar
( m8 I6 Q4 u2 [8 ]( h& dText5.Text = Text5.Text & sVar & vbCrLf0 r6 o% p4 C, G8 D8 P: |
Wend) f& W: r1 n* [
Close #FileNo
. }( j4 V$ u' d& B1 Q, }2 x/ ]+ L8 ]MsgBox Text5.Text( O( v; s9 |* L0 Z; k( e3 k+ _
End Sub& U) J4 k! ^# l/ ^' c& a
Private Sub Command8_Click()& v+ ? G" w& U" A: D9 |
MsgBox "考拉制作!"
, l4 U2 v |; B9 d4 M/ MEnd Sub
# r9 ]$ ~ n! x" d+ tPrivate Sub Winsock1_Connect()
$ s# c) u, k5 J }, fText4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf
) o6 i$ j! A6 c% ^; D4 l; k8 |Winsock1.Close/ B5 E: n( ]/ t% A$ V8 f; d4 d+ s
PortNo = PortNo + 1 [8 d; E3 h6 j" ]
If PortNo <= CLng(Text3.Text) Then0 w, M6 i& y5 c( d6 ]
Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo/ E( I9 b) K) o7 n% b( i1 n: b2 D0 a
Else, s* U8 w0 f' L" d. |- a, @
Command5_Click
, w$ G7 N. s* y9 _End If# d& _1 W. h% ]) J6 Y& `5 Z
End Sub. i% Q6 g8 y! p7 p5 P' ?7 W
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): N) e) N a. l; D
Winsock1.Close
2 V7 n1 S$ a' P$ SPortNo = PortNo + 1
* o# ^ S3 ]% o8 V* {0 h) a5 U' X! SIf PortNo <= CLng(Text3.Text) Then
. K/ e' P7 C% w2 y# gText4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo
( f7 D' R( t+ S! S+ X- C2 p. \Winsock1.Connect Text1.Text, PortNo
3 U1 a2 e2 d* `( E7 h5 P. b& tElse
- v' B3 E/ q* g5 W; UCommand5_Click' n( A9 `" {6 ?; w8 c9 n
End If/ r: j) W4 n8 F8 E8 t
End Sub
3 a: Q! f" ]8 }8 J0 K; }2 v# y* ?8 C5 @1 y5 q3 [' v. P7 K N: D
Private Sub Command1_Click()
; i3 |# W$ J1 ?- ~Winsock1.Protocol = sckUDPProtocol
0 T9 C4 ~# B1 M" rWinsock1.RemoteHost = Text1.Text4 Q7 Z, X# V% Z! L
Winsock1.LocalPort = CLng(Text2.Text)
! P6 G2 V. p jWinsock1.RemotePort = CLng(Text3.Text)9 q- C/ n$ V# ?( N5 T
Winsock1.Bind# K, M! F( d3 \5 H; x( P8 `
Command1.Enabled = False0 U3 V% C- t( _
Command2.Enabled = True
8 |) s( \# Y! M* h' r5 X' D& w9 hEnd Sub
" r9 o/ X6 Z4 H; J) ~' `# YPrivate Sub Command2_Click()$ D U% p: c) {9 h
On Error GoTo ConnectError
5 a* i9 |3 i) q g& Z' mWinsock1.SendData "Koala:" & Text5.Text
8 L* i; A+ L7 Y, P# v# P& |7 vText4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text
) ]9 u. [' Z" t# SText5.Text = ""( T# J5 |' K T- m' t
Exit Sub+ u1 P7 U7 A7 |( t
ConnectError:
, |# ^) y- Q. {2 l K6 f' @MsgBox Error_message( l/ ^9 U3 ~: ^7 d! n
End Sub
& L2 r3 P) ^" D4 ^Private Sub Command3_Click()
$ b) Q/ K3 g( qMe.Hide* `% q& V$ |3 `" A! `; a. N
Form1.Show
" K) a, i( [) T: f* MEnd Sub
% h, r* i; ], gPrivate Sub Command4_Click()
$ e( g3 r/ b! EEnd
& @2 }: K; H9 Y% {5 ?End Sub
7 A0 q8 V0 M# z" HPrivate Sub Text5_KeyPress(KeyAscii As Integer)
: B1 u- ]) Y- Z- l* f( h9 _( o2 H7 UIf KeyAscii = 13 Then
. S' Y+ _3 ^+ |. S* BCommand2_Click
+ o, M2 Q% z( t& I( S4 {End If
" \% q7 x" L; r# I& h* z0 }End Sub' m) J' \- Y* H- G
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)* A5 i, t( `% O& R c
Dim sVar As String: n( @9 ]1 L: O7 {, P- R6 F0 `5 @9 g
Winsock1.GetData sVar, vbString
+ r5 O$ @3 Y- [4 D* vText4.Text = sVar & vbCrLf & Text4.Text1 ~9 b( C* S9 o8 U3 q) Y( C* y
End Sub; C% M% ^3 w$ a" S
& [( l3 E6 k: S2 Q& R N1 _
7 v, C/ | b" W) k, Z( r! i9 Y* m2 z' A$ b8 D) r, C
- i9 G% m* l- E. a `* C
g, }7 F3 P9 |5 k9 S9 I& k [此贴子已经被作者于2004-5-12 20:16:53编辑过]
* h& U) j+ L' P; X* r1 U8 H3 g |
|