下沙论坛

标题: [原创] 我用VB做的计算机网络通讯,winsock控件. [打印本页]

作者: 考拉    时间: 2004-5-12 12:43
标题: [原创] 我用VB做的计算机网络通讯,winsock控件.
在XP下VB6.0运行通过,有兴趣的看看……
7 Z# [7 e! g6 K2 A请点这里下载
8 O1 o. e+ D1 G* K恩啊……先打开后保存……
1 r4 e  @; k* u: G; w$ g" ?- v3 z. R  _- R9 O: J. ^
. n" r5 q3 V! Z$ {( f

3 K! t% a) c4 O6 o6 W! }, ~. ?9 N* r* o$ `
/ Q, y# V# D  ~2 P
[此贴子已经被作者于2004-5-12 20:15:18编辑过]

3 R: q( q; z' t
作者: bruno1122    时间: 2004-5-12 19:17
在哪里呀,给我看看
作者: 考拉    时间: 2004-5-12 20:15
Dim PortNo As Long 7 \! p; ]' o! {$ m o: u8 BPrivate Sub Command1_Click()& l. X2 h4 ~' ^8 w2 n) x I3 x7 k MsgBox "您的IP地址是:" & Winsock1.LocalIP1 [. u1 ]2 x( z8 Z0 p: w End Sub* i5 U" s" M' U U) m2 G0 d Private Sub Command2_Click()' k+ Z+ X# l. S4 Z; D4 b- b MsgBox "您的计算机名称是:" & Winsock1.LocalHostName8 G, x5 u8 i( W9 h End Sub$ a' x0 p6 X- ^+ e Private Sub Command3_Click() 0 C8 K5 B, |9 V/ N4 V: ^) dEnd. I' k% w. `/ `; [9 v! W( O End Sub + j0 @' ~$ h. y" {. h" Z# mPrivate Sub Command4_Click()* C. n; L6 v$ E1 t2 y PortNo = CLng(Text2.Text) - 1 ( j$ c/ ?$ Z3 k9 PText4.Text = ""' l: A& e% V- j Command5.Enabled = True4 f* h( z, y& c/ w Command4.Enabled = False/ R/ R' `+ P; P, } If PortNo < 0 Or PortNo > 32767 Then" m h$ l) o6 N7 D! p' T/ J+ T MsgBox "您的输入错误,端口超过范围"' K" I% F! s9 G5 H% C Command5_Click 1 u7 d2 [$ q5 N% o9 a4 I2 `Exit Sub 6 T! v% d( E3 B* n, }0 n. e, i# [, y, hElse ) x* V. Y! ~8 J/ y! c7 @- Q iWinsock1.Connect Text1.Text, PortNo; W; l8 a) F: q( m, K2 V Text4.Text = "开始端口扫描......" 4 h1 N: t: M- _+ f/ \End If , {4 H% ]4 d; k/ m" I" vEnd Sub 6 m e; f( F+ c0 V$ o/ o2 dPrivate Sub Command5_Click() K9 V5 c2 \1 @+ f Command5.Enabled = False7 X! o9 r3 ]2 l) ]9 R Command4.Enabled = True # ?& x7 i, |8 E3 d3 SWinsock1.Close% w5 K! ^( `( D f7 R0 E+ W3 I. s Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" 5 u9 s3 S5 H, n+ s; A) w( P8 m wEnd Sub" f* V" ~3 ]# R# C Private Sub Command6_Click() 2 I4 q. E: `. O$ k# pMe.Hide * {9 p# _3 ]: H& ~7 o1 m9 q8 DForm2.Show' b) b# i/ y% J" A$ ~5 Z4 F5 e End Sub- D4 D' b3 h4 J, J1 ?6 T Y Private Sub Command7_Click()9 G6 h4 C" j9 W9 K- l FileName = "d:\ipdetail.txt"4 W- R D* n/ Q# I Shell "command.com /c ipconfig.exe >" & FileName, vbHide* i& e! Q8 O; S/ ]+ F: j& B7 \9 a2 n# \ DoEvents . o# T+ R( y2 A0 rDo While Trim(Dir(FileName)) = "" ' A! S$ ]: U+ } j( [6 Y" qDoEvents, Z; O5 z* O# L+ x8 \& h5 [ Loop% ], T S3 D* {0 \( ?8 o4 ] Dim strstring As String, FileNo 3 V) C/ {( J7 r) W* VDim sVar5 j( K$ G' u/ }! q! o F: w If Winsock1.LocalPort = 0 Then" A3 D& [& f. w" Y% Z- V strstring = "端口编号未设置!" C9 W; @& a' oElse# l1 h0 _7 D6 z8 K: k& x% A9 O# ~ strstring = Winsock1.LocalPort d' {( t5 |# B) { End If , v, H% z3 j0 j' jText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf- j/ R+ `3 u9 U; S( R, H/ r5 O7 p Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf# V. |, h2 i' W& l Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议") - e* F: g0 `# \) @# B+ A% _& ~FileNo = FreeFile() 1 K+ T/ S/ V! c+ EOpen FileName For Input As #FileNo3 l8 j6 ?' A( | While Not EOF(FileNo) 3 H$ [8 ?+ P) v0 ?: JLine Input #FileNo, sVar 1 g+ y5 m$ {1 ?! m( K% kText5.Text = Text5.Text & sVar & vbCrLf) t. i, v9 y6 e4 i3 a' m* @; F Wend/ G9 r p7 t6 ]' V/ n Close #FileNo& V# r/ u" j+ X/ } e3 d+ Y MsgBox Text5.Text4 V' O- N E7 W+ g4 K; _/ x8 N End Sub! }; g" Q1 z. T, l+ }; S) m+ T% Y Private Sub Command8_Click() 6 |/ x+ i# F( h: E, rMsgBox "考拉制作!"3 m6 X- R% O" N) M End Sub/ \' C% O; ?, o) S, @" c; @ Private Sub Winsock1_Connect()- n3 P' E4 u5 ` Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf- C" I; y [2 B3 T, e3 ~3 o5 W7 A2 h Winsock1.Close4 @' K& G( r: M' _& p9 L7 q4 l2 `7 W PortNo = PortNo + 1: y4 D9 t6 @& H If PortNo <= CLng(Text3.Text) Then 2 o6 h, i3 G$ A, s5 ]; E% {+ TText4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo + M2 O. G, w) f( @Else7 p( i* w* n: r; F* L Command5_Click* e" E/ A% q$ T- d! e% j# ^8 P End If 1 e8 M$ f: J5 ?9 M2 G4 rEnd Sub ( l' B) m( E! A( @" ~' I. ]8 q* aPrivate 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) # `; D2 z+ V4 q# rWinsock1.Close9 h% p/ o' o/ D7 l: N PortNo = PortNo + 1 ) m5 l1 \ h& J. T9 xIf PortNo <= CLng(Text3.Text) Then 4 }3 c6 g% ~, g; mText4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo/ ^5 o; s: B1 T A3 v/ R2 r/ _/ l0 S Winsock1.Connect Text1.Text, PortNo 0 x1 c9 w) J6 L( M* Q/ n, zElse + q- |4 v2 v! q# K* W( @& gCommand5_Click 1 c) a( t3 K! y3 x" L- BEnd If* R5 k9 n& Q5 I/ A End Sub; E( q0 O& j) O# x 9 [, b# l9 ^$ xPrivate Sub Command1_Click()2 i; ~/ C! p( p9 X Winsock1.Protocol = sckUDPProtocol 6 o) A* ^# I$ g8 G* ]Winsock1.RemoteHost = Text1.Text# c5 q: q3 _" e8 S" k8 G8 r4 j Winsock1.LocalPort = CLng(Text2.Text)( P' o3 R! i( e8 U7 L Winsock1.RemotePort = CLng(Text3.Text)$ f! l& L8 @! z+ v" Q Winsock1.Bind) R* x$ W) ]9 a O7 I Command1.Enabled = False # r; S/ L R* U+ c0 C& VCommand2.Enabled = True ( y& K: n3 J; [# `% iEnd Sub% Q" m2 a) U% |# }3 Z/ S Private Sub Command2_Click(), m. F% l) M5 h" h On Error GoTo ConnectError " E: V- Z$ K6 X4 _- B6 _Winsock1.SendData "Koala:" & Text5.Text2 e( z' g0 o0 [; u$ v Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text5 a# G( h1 y" r. L Text5.Text = "" g# H, |8 k1 b$ U% w% M0 [ Exit Sub : m$ C9 I' L6 E* G9 zConnectError: , B% i3 K. \. I( ~MsgBox Error_message / z* M; a3 G0 V I" o8 `2 F% HEnd Sub ) l- `. b( Z+ l4 o) B! N2 [9 w mPrivate Sub Command3_Click() 8 X( J$ j t/ C# |Me.Hide # e$ i% @ z, Z( f9 ^0 fForm1.Show& S3 I. J/ R& V" [- O# f, Y- V/ X End Sub 7 b; M4 e2 L/ M7 l! IPrivate Sub Command4_Click() , r8 n, [8 K! h3 }. P; N: u& NEnd" u. O. W" D# m0 U/ T. ]/ I; _ End Sub3 Q# a; T6 L, U0 @) c Private Sub Text5_KeyPress(KeyAscii As Integer)* T4 z0 Y: q3 F# T" ] If KeyAscii = 13 Then ' o7 s6 ]' D3 ZCommand2_Click + N+ _% i- l5 w# [4 V. R! OEnd If9 [& @, W0 S% ^' L: ? ^/ p End Sub * Y8 G& y8 E- t( vPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long); p. K& K6 G2 \+ J( T Dim sVar As String " U: v; Y7 l3 U. |% j$ \Winsock1.GetData sVar, vbString+ V6 g5 c& k7 h p Text4.Text = sVar & vbCrLf & Text4.Text6 |% t: e! _3 I5 z$ f9 F End Sub : H k" O! o8 j, ^ . r _7 j% }" Q- g8 E M* b' t. E+ p9 n5 m7 x [ 1 R0 p9 t0 B0 l( `5 | : q$ u0 y7 Z/ b% Y" X( u 6 m% C' [& Z; Z6 T/ `
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
& t7 B7 e# M+ m0 j9 M2 z




欢迎光临 下沙论坛 (http://bbs.xiasha.cn/) Powered by Discuz! X3.3