下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……% z# |* e% C, z
请点这里下载2 W, f, s' _+ a' i8 @
恩啊……先打开后保存……# q8 a5 n: V+ R- J1 {* u# ~

4 t% }" M+ }2 J- s0 f  H$ b* F& f6 U9 N; h+ Q  E. N
4 G- H0 t* m- K; L# @
9 R6 E  f% \- G  o; H0 J& O
( |* _; G  R: t' y: _
[此贴子已经被作者于2004-5-12 20:15:18编辑过]

* n, O3 S( Q7 v" D6 {8 [
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long : y2 M- z, P: Z- aPrivate Sub Command1_Click()& T: v* _0 Q1 u7 n% s4 t& `( R MsgBox "您的IP地址是:" & Winsock1.LocalIP $ c% E/ O8 O# U) f4 P1 CEnd Sub " m/ ^; D: T, O. W1 OPrivate Sub Command2_Click()7 C# O! C2 \9 C+ J* T0 B0 i/ b MsgBox "您的计算机名称是:" & Winsock1.LocalHostName ' U* T4 H; x* C: y \' j8 N# Y# D0 QEnd Sub 7 Y4 l5 r4 H1 v: Y) F! f( zPrivate Sub Command3_Click(). b$ w1 K: Q, m; a3 C, [1 l; ` End 8 d1 D, J3 r1 [; \/ |5 F$ K2 b' aEnd Sub " N: w+ p" z" x9 @Private Sub Command4_Click()( R7 {! n* U2 E+ X% t% { PortNo = CLng(Text2.Text) - 1 % Q' M" c& I+ h# a. CText4.Text = ""/ e# x( n2 M7 R6 N4 | Command5.Enabled = True5 u! ]/ E* R2 D8 j" ]$ i Command4.Enabled = False# D' R3 Z! h: Q* |! H If PortNo < 0 Or PortNo > 32767 Then7 L; z% p7 ], \( [ j$ { MsgBox "您的输入错误,端口超过范围"" u) s7 ]# b' }! X Command5_Click# D' V& O" o; K1 K* l Exit Sub ! B9 o0 l4 y6 ]7 D+ M4 ~' VElse 6 T) E8 y( z0 [7 yWinsock1.Connect Text1.Text, PortNo : f: p/ c; a2 n) X H8 B0 WText4.Text = "开始端口扫描......" 7 A4 e3 m i* f9 }2 |7 P$ s. X2 SEnd If $ H& j# |& F) _; y* O7 @0 GEnd Sub ' l# O+ E! k( ~; t/ IPrivate Sub Command5_Click() 5 e, K# b7 A* M) k+ q4 ]Command5.Enabled = False ; W7 y5 O: k9 c+ `; K4 ECommand4.Enabled = True 7 S1 K8 T4 b3 [Winsock1.Close0 ?. q1 |, h9 A2 p L Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" 2 z$ h- [* z4 E8 z1 ]3 I/ d% iEnd Sub9 h! x9 b0 U0 k6 i, H4 w Private Sub Command6_Click()" p: a9 u9 s8 U( c Me.Hide ' w+ [' S& ?! BForm2.Show3 W! U1 g3 a$ f. q" n End Sub , U% C) V$ m' h; B5 BPrivate Sub Command7_Click()5 _7 F/ f! q% P: {8 T8 _ FileName = "d:\ipdetail.txt" . {# m# R9 y" z6 W; [Shell "command.com /c ipconfig.exe >" & FileName, vbHide0 T# O. v% @; {# w* }) h DoEvents! h- O: t9 v8 y9 x/ }( r8 B; P Do While Trim(Dir(FileName)) = ""! x8 @. D% B/ V+ A3 z7 `9 f- b DoEvents6 C6 U6 e; ^7 P* r Loop 8 T3 {3 G5 j1 N6 L! mDim strstring As String, FileNo . O* {- p7 Y. L% HDim sVar) i0 z+ t8 a, y. ]' a* e If Winsock1.LocalPort = 0 Then0 D# s w# o8 q( T: z* _$ o1 S strstring = "端口编号未设置!"7 [- ~% G! T) x! j, m! \ Else / \* a4 [6 |$ \" h, I: lstrstring = Winsock1.LocalPort9 y! B V X0 u8 U End If/ k( v1 f* h4 ~: f- [+ ^/ O1 S Text5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf. T0 ~3 Y' n l, V Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf ; S* I1 c5 u6 k; L j- b7 T' ZText5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议") p* y" F O) t- p( T3 eFileNo = FreeFile() ) T, D2 L2 M+ e+ X) a: c4 ~Open FileName For Input As #FileNo& r$ R/ J) T8 c# h9 P8 B/ C2 H While Not EOF(FileNo) ! Z4 J8 Y8 t3 `! s* M P- P. HLine Input #FileNo, sVar 2 q2 L0 m2 r$ l+ L. f! EText5.Text = Text5.Text & sVar & vbCrLf( X# P, E% {# G# k" c Wend / Q) X( C$ \: H7 c7 eClose #FileNo9 Y% \. q8 W0 t H MsgBox Text5.Text + ?1 G; H# u9 M# z9 [End Sub5 t) k- V' e* P( \0 d5 E Private Sub Command8_Click() ! X) `! E; j6 UMsgBox "考拉制作!"9 ]; h4 [7 O s: G4 M8 k End Sub & y+ f2 W$ p1 a( T/ f' D. }! U3 N& KPrivate Sub Winsock1_Connect() 0 A3 ^( H4 e4 l5 f' Z bText4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf % b8 B' \3 _' d; D% `4 ]4 pWinsock1.Close 0 O2 e g! Z. M! |9 Y6 FPortNo = PortNo + 1) V( ?( {, `/ ~3 d1 ~2 N* O8 T( F5 z5 P If PortNo <= CLng(Text3.Text) Then , p _5 F9 H% u3 HText4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo7 ?( U' r% i4 g: V4 b K, E Else ) m( J1 g0 B' U5 C5 WCommand5_Click. E8 a# O0 L' S& S8 a8 B8 G, T7 `( J( B* h End If; o% U5 G( h- Z; M End Sub 5 n, W# @4 M+ m- |" T: a5 mPrivate 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): i. f9 h& k: F Winsock1.Close7 E. U% ^: {: D! G( Q PortNo = PortNo + 1& `9 `9 ]7 O$ y& o$ g6 g0 v If PortNo <= CLng(Text3.Text) Then& g1 q: b: W* x7 _, X/ g9 L Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo - n2 V7 J0 a' M$ t9 K: LWinsock1.Connect Text1.Text, PortNo5 U) B, t+ K# g* A ~$ M Else 0 V4 h2 ~2 k" [* _( r6 w- \% }# NCommand5_Click 7 y0 w+ g: T" ~ V9 oEnd If6 H: G/ ^; d) N. m End Sub9 C o. N k! ? 2 J& a! @/ A& G4 l9 V8 @0 TPrivate Sub Command1_Click() $ z2 d3 I1 ^1 {/ o( t4 K7 MWinsock1.Protocol = sckUDPProtocol3 I8 J. L" A) }9 b$ C; y Winsock1.RemoteHost = Text1.Text* x, u% N: J2 L# Q) C+ o; y Winsock1.LocalPort = CLng(Text2.Text) 7 C8 _6 B$ |9 i, [) ?8 E' FWinsock1.RemotePort = CLng(Text3.Text) 6 m$ w0 m. { C' l* \% {Winsock1.Bind * \, J- k/ g% O# j4 V, g! kCommand1.Enabled = False 6 T( s, q9 }/ k: O$ M% Q4 ~Command2.Enabled = True) L( Y0 k, x! K End Sub2 Q* R$ P- I7 E `+ F+ w1 U Private Sub Command2_Click() 5 V- _1 ?5 ~! S1 ]% r; s+ Y+ KOn Error GoTo ConnectError 2 E! E* t/ y7 h6 p" XWinsock1.SendData "Koala:" & Text5.Text 4 ]9 {: X& y+ J7 a. {( dText4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text6 `( ~5 b8 D6 v2 H. f* L Text5.Text = "" 4 w4 |( R- C+ j% B1 L k) u1 pExit Sub" W0 E+ S( r: y% X. M* k ConnectError:' A' u: N. y. N2 i& {$ \, ]3 U MsgBox Error_message " E. ]1 \& `" \2 M* D7 n! AEnd Sub1 _- U- i3 n& @; @+ W1 l; h Private Sub Command3_Click()( D3 w( ]: y. {6 `$ N Me.Hide 3 b0 V$ Y- m) kForm1.Show% X$ F* k* Z# l L F- O" ^4 ` End Sub % ]$ [ I0 _" c: [, qPrivate Sub Command4_Click() 6 X" U% a' d' m9 X( gEnd J- ?( }) F# _ End Sub $ ?- t% c- A( ]1 ] JPrivate Sub Text5_KeyPress(KeyAscii As Integer) I: B% |4 I5 H) W1 q6 U/ U Y If KeyAscii = 13 Then* f$ [* i6 U8 C' {1 h. R: N' W0 G e Command2_Click % A! p& ~2 H# N' o- ~- ~. D8 SEnd If . k4 H4 e, l# {) Z. D' ~( H% z/ REnd Sub# g5 t8 U% ?7 ` x9 i Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)) L* `/ O* e5 E9 _" k Dim sVar As String / _9 f% Y5 c; S: fWinsock1.GetData sVar, vbString + m( r3 M' W9 H# K, R1 C5 lText4.Text = sVar & vbCrLf & Text4.Text : E, A' z. z/ ^End Sub $ a% d5 C2 P; \( S $ p0 q& n# S/ C. W0 S$ S4 r ) Z! m7 r) C* ?) E4 F) ^, i0 L9 e3 B9 t8 x( ]. R % L1 L; \: X3 W. t : p* `9 ^. ~1 u7 ~1 z! ], L {
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
3 Y9 g0 z; f4 R. J

本版积分规则

关闭

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

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