下沙论坛

 找回密码
 注册论坛(EC通行证)

QQ登录

QQ登录

下沙大学生网QQ群8(千人群)
群号:6490324 ,验证:下沙大学生网。
用手机发布本地信息严禁群发,各种宣传贴请发表在下沙信息版块有问必答,欢迎提问 提升会员等级,助你宣传
新会员必读 大学生的论坛下沙新生必读下沙币获得方法及使用
查看: 2842|回复: 2
打印 上一主题 下一主题

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……1 l+ Z9 ?$ a& \+ b& z" U5 k
请点这里下载0 J, V# A" R+ ^/ |2 Z( L4 r8 Q% i
恩啊……先打开后保存……
8 V4 ]7 S! K& @, F+ @+ n% T. o+ k
: h. |& V% E% x. s7 R* \. ?$ V7 a6 L1 v5 w2 f' P3 @$ |, w

% m. b9 {% M$ R0 m/ [/ e$ o; I+ W$ g$ p8 v# M) _7 {
, h2 g) z2 [+ y+ E0 Y9 w' t+ \
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
; D/ _; I1 p% [2 }7 i0 c
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

2
发表于 2004-5-12 19:17:00 | 只看该作者
在哪里呀,给我看看

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long7 v4 b- F4 M% m6 H Private Sub Command1_Click()1 |" B ]4 v! B5 b# t H0 }) b MsgBox "您的IP地址是:" & Winsock1.LocalIP3 p O- O3 {% t& q End Sub 8 c# d6 N7 b: D5 f9 e3 a4 PPrivate Sub Command2_Click() 3 U6 b& f3 j) |6 l1 H. [MsgBox "您的计算机名称是:" & Winsock1.LocalHostName ' T5 w. p& F. e/ I2 j+ yEnd Sub' [3 b% q& N' \/ u, A( R Private Sub Command3_Click() & q" r6 s% m& L$ f% lEnd 3 P3 s' p% V0 D+ Z6 G0 N9 i3 EEnd Sub5 c2 ^1 U5 n" B* h+ G7 b Private Sub Command4_Click()1 V/ s7 k$ T3 p" X( c PortNo = CLng(Text2.Text) - 13 ^$ u& y1 e# G+ e. R Text4.Text = "" & r0 A! G6 h9 V, d, A" \Command5.Enabled = True * [: H5 ~2 v; }- w, [Command4.Enabled = False . C7 m" c- s9 K9 G1 ~1 h% b* SIf PortNo < 0 Or PortNo > 32767 Then 3 k* q! ]' c; ?9 g: F) ?- N/ w0 S+ mMsgBox "您的输入错误,端口超过范围"" G* Q: b6 w# o* A! g* L! ~ Command5_Click ( k T2 A, ^$ O- i$ G jExit Sub $ F2 }# W* ^# S! ?( g6 bElse& V% S7 e, b( A$ n5 u Winsock1.Connect Text1.Text, PortNo 2 e: I) C8 ?! L/ L9 x, d9 NText4.Text = "开始端口扫描......"3 W f" R! P. o5 B3 [* F End If 3 V3 S4 E$ w4 ~& IEnd Sub # ^) C# E1 d6 x1 C" U. y, J( f! sPrivate Sub Command5_Click() & o) [5 [/ X* N+ }3 v4 CCommand5.Enabled = False 5 V* T7 m: G+ Y( i1 DCommand4.Enabled = True$ N% Q: E% z" b Winsock1.Close0 W6 F# |6 F, W! u2 q' i: `6 z. C Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。"4 n6 B$ ^/ d/ I7 O" L End Sub' u3 U: |( u5 U2 @0 J! v! l) r Private Sub Command6_Click() ) o3 a K7 b7 EMe.Hide * @# N* \6 |& K+ I9 n; {Form2.Show w; X$ \3 F( c% y$ A) y- pEnd Sub* Z! ^5 Z& n$ G- W: L5 K Private Sub Command7_Click() ) z' V; R) ^1 g7 Q5 p' u4 ]4 H7 C( G6 @FileName = "d:\ipdetail.txt" s: Y' e- A2 ?9 y8 S. I Shell "command.com /c ipconfig.exe >" & FileName, vbHide6 O% m: G$ A/ K' x, y6 I( U& _: ]0 w) W DoEvents9 j+ Y) u* O- D) n0 J Do While Trim(Dir(FileName)) = "" 1 W. n( n' n( I! i# ~) q0 KDoEvents6 K) b7 L+ G! k" Q Loop; i" H) V, o: Z, Q6 A" k$ _. K$ x Dim strstring As String, FileNo( ~' i) |7 X* t9 a# ]- Y; M Dim sVar ! I: M" k) o7 o2 RIf Winsock1.LocalPort = 0 Then' K7 N2 A. n* [. W! B* \' Z# P strstring = "端口编号未设置!"/ B4 m4 f% m- m+ T X% E0 k Else 0 e7 k' b- E4 R% Y3 B8 \strstring = Winsock1.LocalPort 2 O( Q7 _7 Q3 y. UEnd If" Y2 E! T5 b. Z d' ~0 D4 u Text5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf3 n* e5 j1 o8 o a2 w' ]7 D Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf! q" ?$ S5 V" f# B1 s5 ?6 J2 {$ p4 n Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")" w+ {" v+ V+ g/ f. \7 f FileNo = FreeFile() 4 Z, f$ \3 s, t0 b( XOpen FileName For Input As #FileNo0 P3 A( D; ^% ^5 B8 r+ b While Not EOF(FileNo)4 e! C {% J) i: E8 | Line Input #FileNo, sVar5 k9 @; s# J7 H* @ Text5.Text = Text5.Text & sVar & vbCrLf 5 B- s& x5 T zWend9 _4 G# E8 ^; r! `( i0 @1 F Close #FileNo3 M! a% ^% a( N% j' F5 q# G MsgBox Text5.Text 5 g- F z! d% Y3 v& h* @End Sub5 h1 |7 W8 C9 Z. z" t9 h Private Sub Command8_Click()- M+ T* W2 \* O; p1 G MsgBox "考拉制作!"; {2 H$ o7 z& q2 a. k: y1 K End Sub3 N7 n2 I9 v6 Y: ]' g Private Sub Winsock1_Connect()' e: z9 n* W. f! x: [) R6 t x Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf4 r0 ?+ D2 J) t4 l Winsock1.Close ! G5 L) o V2 X6 m2 u$ }8 Z* DPortNo = PortNo + 1 ! }% f# R' Q1 l. h5 W: a; OIf PortNo <= CLng(Text3.Text) Then4 _! k" M) n' I+ F2 p; L Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo- Z: j8 ^4 f$ [* d8 |+ O7 P" ?: U Else$ z: A+ a7 n* m Command5_Click 7 h+ m8 H+ a% E1 z5 q* W* u5 x. tEnd If' g7 P$ |: `8 v. i+ u End Sub) c% \4 H4 w0 N9 |9 L. ~ 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)3 m0 T2 V' l5 i& f0 H Winsock1.Close8 F+ P2 f% x' w$ _) T PortNo = PortNo + 1 ' x# f8 T' i# ]2 o$ ^If PortNo <= CLng(Text3.Text) Then w" m: O/ E) y& M, P9 z6 r Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo. l2 x. G( C& G' e# q) Y1 _; V Winsock1.Connect Text1.Text, PortNo + H& N' m8 g j, N" EElse : `3 U6 ]) W0 d E, h% yCommand5_Click& |& t+ F; t) z( d% a End If4 R( @$ m% N. b6 P1 h$ P! b End Sub 6 W' a2 D% K9 o/ b5 t3 K. x7 R3 p$ g) i Private Sub Command1_Click() 7 @0 G4 H* B+ W8 K% D9 ?/ YWinsock1.Protocol = sckUDPProtocol8 b1 \. j+ `, t) K8 J0 Z W Winsock1.RemoteHost = Text1.Text9 n6 I9 W6 {3 ]% a" h$ W0 O Winsock1.LocalPort = CLng(Text2.Text)/ _" j% a: W) f' s Winsock1.RemotePort = CLng(Text3.Text) 7 G( o$ y: G8 o! S( V7 pWinsock1.Bind5 `5 Y1 D' a w Command1.Enabled = False 8 o. O- B, Q2 A0 F7 cCommand2.Enabled = True+ W$ Q r# _- w8 D4 G% i End Sub # ]$ O2 D7 ^9 D* GPrivate Sub Command2_Click()- y. I+ e3 m4 k0 Z) Q. q6 m4 y! t On Error GoTo ConnectError # A8 F' }- X& j% A6 A' V' X$ rWinsock1.SendData "Koala:" & Text5.Text6 H' @4 I5 S7 i Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text * e G* n' O/ q7 o" uText5.Text = ""7 j& h/ f; {0 a! } Q8 d9 D4 G Exit Sub) I, C2 Y3 ~4 _8 x/ W* i% R. R ConnectError:, b- B+ G7 V0 q" s MsgBox Error_message ' c* f5 p9 _2 j- a6 u7 OEnd Sub - n4 L9 A) \% MPrivate Sub Command3_Click(); S2 n6 q2 q% U Me.Hide$ l+ H% M* A. W) ` Form1.Show ! ]" b8 T9 t8 E; b$ YEnd Sub 6 g: E! u/ P5 P) F! u- APrivate Sub Command4_Click() 6 w) H0 d" f" D7 l" K8 n& SEnd ( ?2 {" l; k) v: s u7 D S# P" zEnd Sub* L' G7 [, j1 k' k$ ]9 u Private Sub Text5_KeyPress(KeyAscii As Integer)$ L" a2 X* J' p) s' E If KeyAscii = 13 Then + i- |. ?' b+ V* \$ w( W& WCommand2_Click + z) t: ~7 R o+ t0 I9 aEnd If' k" R0 q" r& Q# v; K2 L: j End Sub ) G$ q' Y, Q$ ?* Y2 s2 C! D6 [: y! S% fPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long) i2 w2 ~) v+ K6 z% `1 F2 H0 j Dim sVar As String1 {# u4 n( K% A+ s6 a Winsock1.GetData sVar, vbString; C3 i% Z- B, V, k) G% T Text4.Text = sVar & vbCrLf & Text4.Text4 Y; I8 H* u8 M% a2 a* c5 C3 ~) R End Sub - A- w: w* g) t5 \; @) g4 @, {- s/ H2 c1 [ ^/ S- T; i9 O t+ A * B( |; Z2 |: B6 c1 A2 ^+ @: |/ o( h- k1 Y) k6 @4 n+ ^2 D% |# p: y; ~9 H 5 {! _ o6 ~" ^; J3 l
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
9 y$ ?- ?8 _$ K# q J( t

本版积分规则

关闭

下沙大学生网推荐上一条 /1 下一条

快速回复 返回顶部 返回列表