下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……8 K5 P$ x0 q( t& S/ C& G
请点这里下载' L8 J/ x/ `& N  G  D7 e9 f6 g/ _
恩啊……先打开后保存……
# j* L' T$ S5 B( |, I1 I
1 W4 Q9 o& r& [2 c0 y" c- U: H0 [0 I- I8 F- z' Z% D4 C. \

, D0 E, q$ ]  ]: S2 a! m) P
# s. W+ T1 U, L4 I, y* c1 G
. z/ E( C4 U0 V; V9 o
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
! O/ @2 t* j- T9 }2 U! c
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long 7 S4 G' \8 z) S0 O& _* m5 ZPrivate Sub Command1_Click()5 e5 }. y& w/ F' X6 c& i MsgBox "您的IP地址是:" & Winsock1.LocalIP 8 B, N$ G0 a3 V9 }7 VEnd Sub 9 {6 S5 W/ P GPrivate Sub Command2_Click() . w- C+ p8 B |/ ~% K/ RMsgBox "您的计算机名称是:" & Winsock1.LocalHostName3 K, ^5 {1 p0 P' ^' w6 ~3 L$ k End Sub3 R/ B$ b4 R5 u+ {/ _8 O& y# n Private Sub Command3_Click() ) C* P7 u- T e( NEnd 9 }' q/ }6 ~0 F/ {0 j) HEnd Sub: j6 \3 i0 M9 N( s5 y U1 Y5 Y Private Sub Command4_Click() - e. E' N) _* h7 D- iPortNo = CLng(Text2.Text) - 1 p6 T- H$ i, G; @) z: f* I% T! _Text4.Text = "" }" R f7 q f( Y) ECommand5.Enabled = True / x0 a% D. }. {! {1 `Command4.Enabled = False 3 c l! Q4 Y& Y; Q4 hIf PortNo < 0 Or PortNo > 32767 Then2 t, |. z* b2 ?) Q MsgBox "您的输入错误,端口超过范围" ( `2 y4 r) |" q- [" C! L5 NCommand5_Click8 P# [; l8 }# }3 v9 S Exit Sub; \3 f5 i( W& W9 a: n, C Else , V8 z# \9 y9 P+ j4 N" J9 o) HWinsock1.Connect Text1.Text, PortNo2 o4 b# N' ^2 q: T Text4.Text = "开始端口扫描......" 2 W! k- ?; u9 U* PEnd If 2 |. u( O1 P1 c& \, @% ?7 jEnd Sub . x2 W7 I2 o$ GPrivate Sub Command5_Click() 1 a: q# m' e* j1 [! I6 ^Command5.Enabled = False! G& Q0 q5 m" U) n4 H% ~ Command4.Enabled = True 4 v8 j- _" O& _) q3 t7 y# c( eWinsock1.Close6 L- P+ \2 y; m( I t3 n Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" : p8 z5 t, a3 R s$ d* K/ \* GEnd Sub 8 x! J7 V* q/ h. S4 Y% LPrivate Sub Command6_Click() # f* w0 T, B# r# IMe.Hide 0 ^- a+ z) q' _/ Y; h$ E* dForm2.Show/ \4 Q% v9 {$ n) m& q2 ^) E End Sub' B$ Q4 y$ K0 [1 k ] Private Sub Command7_Click()2 k; H' O* ?% h2 M) j6 n" R FileName = "d:\ipdetail.txt". q- \$ P! J3 C Shell "command.com /c ipconfig.exe >" & FileName, vbHide - F# |7 t5 M4 a+ w6 R6 H$ E5 `DoEvents$ o/ D' O+ L. n& b9 A& i& U( ~- ?- q Do While Trim(Dir(FileName)) = "" / E. u I+ [- r7 p) x( C: M" X0 [# eDoEvents ) b9 Y+ Q" U9 j* OLoop6 f/ w7 t+ C6 p$ I6 D Dim strstring As String, FileNo4 [" s& ~* T5 U" N5 E+ _ Dim sVar & y; s6 O$ E% p- {If Winsock1.LocalPort = 0 Then( p6 H4 l+ }3 ^- k" ]6 | strstring = "端口编号未设置!" . d+ H, M5 s9 F/ e* W6 J) ~$ _2 CElse / g* ^( g5 y" i+ _, g% z/ z5 y1 gstrstring = Winsock1.LocalPort3 J; z1 r7 o9 T End If2 J) D* |+ X# w3 m Text5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf 9 V3 x6 ?+ z7 g: D# v4 I S8 s9 h+ N$ xText5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf + [' I# h, _% xText5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")7 _7 `3 `. k" M, o. T8 p FileNo = FreeFile()/ H- M2 `7 R( ] Open FileName For Input As #FileNo # F& M' k7 e, c! {# Y, FWhile Not EOF(FileNo) 7 y5 v- ?9 G& u/ p$ d! J% {( n6 f2 zLine Input #FileNo, sVar r1 t: I4 e5 S5 o+ U# Q" [6 oText5.Text = Text5.Text & sVar & vbCrLf1 y" N4 y: ~; b. u7 v1 J Wend # n9 W" s9 o. [1 T9 @1 \Close #FileNo% ?* U) |2 K, u& M! W1 _% n" ? MsgBox Text5.Text0 X0 t0 c7 a- N# D" y, p End Sub $ {( C9 R! Q) o3 O$ yPrivate Sub Command8_Click() " Q/ p. x0 x# XMsgBox "考拉制作!" 3 z" R7 I9 k; z F3 N: M. E/ NEnd Sub ) ^) Y: W9 j4 u; F9 kPrivate Sub Winsock1_Connect()1 q+ @/ U* H1 ?- v Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf % G V# L' G2 ^Winsock1.Close6 f" h; j {( b, g4 N PortNo = PortNo + 1 1 Y- u A8 Y- @ e* w) Q4 _. KIf PortNo <= CLng(Text3.Text) Then 0 x4 e9 W& I, FText4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo 6 V4 I* D- n- ?Else% e3 e2 E: z0 Z/ I4 h5 d! i3 P Command5_Click 4 w- P$ X: }( |. I- m0 \! [End If: p+ @1 k7 L! u8 L End Sub7 {, k% h* X {* c9 i! _9 r 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)7 o) H( p% ?* g Winsock1.Close . F, n3 p1 K. B/ c1 C% `2 b# uPortNo = PortNo + 11 T; c' i. G7 T; j# p4 U If PortNo <= CLng(Text3.Text) Then 9 B+ Z. @6 i; A3 t( H/ AText4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo # ?9 C% l2 X/ LWinsock1.Connect Text1.Text, PortNo 4 f6 ?" p" L6 h: s0 AElse 5 x& l* j5 `1 y* k3 l1 GCommand5_Click) f6 |: Y" k0 j# T* { End If: A3 c. ^( B7 j0 l/ N( R! i* w End Sub$ B; {1 p4 K0 I* O% M 8 A, B" C0 H' F2 h$ ?7 O9 ZPrivate Sub Command1_Click() # ?, Z: t; m. N, O% j# |6 SWinsock1.Protocol = sckUDPProtocol 2 Q! g3 H8 b. U+ i" q0 R @, Q fWinsock1.RemoteHost = Text1.Text , s3 B5 Y" A+ eWinsock1.LocalPort = CLng(Text2.Text)9 K! f+ m% @) I% V# } Winsock1.RemotePort = CLng(Text3.Text), X. m2 Q) M) K% [- C' a8 _7 Y Winsock1.Bind: O* l" n \7 ~+ [ Command1.Enabled = False ! o5 G: |0 L5 @3 j0 |: p" zCommand2.Enabled = True , z% X+ V8 j; }# h1 }# fEnd Sub5 @6 K! r, D# ^ Private Sub Command2_Click()7 |$ \' u' u6 s& @! G/ T8 e* Y. B6 J2 H On Error GoTo ConnectError5 {0 X- s! e0 Q Winsock1.SendData "Koala:" & Text5.Text : i* `8 P2 V; W% V# AText4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text $ K; y+ [3 }1 r/ R/ t0 ZText5.Text = ""+ | a" P" L% O- m) H% Q0 | Exit Sub- K, t! b' M& F- ^" p ConnectError:. o& j- J3 N! Q% [/ _' A) Q9 F MsgBox Error_message7 @ F, A& k+ v+ P. h- Z$ X( V End Sub* i7 I" z! Z7 |! H6 }' \' z3 r Private Sub Command3_Click()/ N8 S& m3 `) ]3 a Me.Hide! Q: E! Z/ Q, J" w9 L Form1.Show' w6 @- w2 W, K& b* c/ s End Sub1 J! i4 j" k! f* Y* p3 e4 Z8 h/ D. J Private Sub Command4_Click()% ?" D5 O a' K7 Z& P, A' ~$ Q End( T3 x1 T, z$ T5 k9 c8 ^- C% ^* k End Sub2 t7 u9 S0 h* L" q; Q$ ~ Private Sub Text5_KeyPress(KeyAscii As Integer) ! U1 r& ]8 h. x/ KIf KeyAscii = 13 Then 9 V8 f% |5 |* t& f. cCommand2_Click 4 W! p- H6 t; o" I8 Z$ @End If% c* h9 p W- l: x End Sub+ g, E; N9 u( ?4 m2 I0 O& h# \ Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)" Z# ]3 T9 c7 Q- ~6 M) e Dim sVar As String $ L6 @" _; N' ~( RWinsock1.GetData sVar, vbString ) }7 M, C: n* w9 t! pText4.Text = sVar & vbCrLf & Text4.Text 8 }6 q! g: {+ f) e& P+ rEnd Sub9 E* y4 ?8 D( `6 j' { 2 b) {+ H0 [" p5 Q O5 z( O; o1 ]! D' \4 e ; U5 ?) A& f5 [* }" w z ) a1 Z+ N" v% V( l' d8 }: ~ $ n8 l. C3 e1 w
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
6 j% |. E/ b4 y ]/ ?. ^' t+ W- P

本版积分规则

关闭

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

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