下沙论坛

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

用新浪微博连接

一步搞定

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……
6 V0 k( G& S3 e- O# I$ v请点这里下载% ?: T  z6 Z9 J- Q5 c$ M
恩啊……先打开后保存……
/ J& p* Y# v( |, e8 D6 I
4 l4 ]' y4 u9 R0 h7 X6 s+ |# b# V3 x  }+ b4 _0 l2 R
- ^: v  a! x# `9 e, k. N3 _" O

: c; |* M* s/ p! q2 B2 o
( f. J6 h; L0 g7 m3 ]
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
# N! \6 |; S( o( l8 V% h% j
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩 转发到微博

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long % j) s5 Q1 L/ K a cPrivate Sub Command1_Click()7 Q, \- {5 N- G8 \$ W MsgBox "您的IP地址是:" & Winsock1.LocalIP ) |( }$ x* K) T8 TEnd Sub, ]3 Y1 F* k7 I Private Sub Command2_Click()% k0 C/ z. N1 o, l MsgBox "您的计算机名称是:" & Winsock1.LocalHostName/ b& N7 h; x i5 S3 M End Sub0 [; `' Z/ |# W. k% c: `# U Private Sub Command3_Click(): E: R; j. Q- J. i- d End ! S: H3 c8 l- S* p6 R) PEnd Sub; }% V6 f' j6 y& N, q6 a2 t) M Private Sub Command4_Click() 4 F# J; t4 x% cPortNo = CLng(Text2.Text) - 1 1 N" ]2 a' Y/ t2 G0 K' VText4.Text = "" - ~) [9 o; k. V; w9 n7 {1 gCommand5.Enabled = True' e6 f) ]5 M# L) O, f4 m! T- K" \ Command4.Enabled = False" [+ C( z9 p. I( s0 X- v8 A If PortNo < 0 Or PortNo > 32767 Then & a, |! {2 |; _+ i( A0 q5 X; bMsgBox "您的输入错误,端口超过范围" & m0 N/ ^4 ~- H" b7 ^3 bCommand5_Click $ Q7 k: n+ k( M$ _/ qExit Sub. s/ G: z' n' M Else & e" `7 ?; E2 w% DWinsock1.Connect Text1.Text, PortNo, n1 ~, {4 ]2 F8 h% J Text4.Text = "开始端口扫描......" 2 Z/ ~9 P( [4 @3 _/ [9 sEnd If $ X" b, s! Q9 l; L6 B iEnd Sub " J4 k1 \8 ]% T8 ~Private Sub Command5_Click() 5 {* M+ A* D* ^0 Q4 N' v5 ZCommand5.Enabled = False/ E1 Y$ f! E. T( G1 |, ^* \ Command4.Enabled = True. u# [( g: Q8 u4 l4 p; u" Y# s Winsock1.Close ! O b0 |7 J! a1 e1 I. Y& m. }; MText4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" H, d+ r( T+ u( I: I End Sub9 g3 ?) P& ?3 \4 p2 G0 Z2 | Private Sub Command6_Click() / S+ x6 {9 c' C6 }+ @/ [8 f cMe.Hide 7 w# f0 q( d" bForm2.Show7 t' I; \# W2 D; J4 ?, L5 l End Sub + c+ C5 x) i* o1 v( r" A6 u* Q) kPrivate Sub Command7_Click()- _ w' \) @9 |& ]! z( l' b FileName = "d:\ipdetail.txt" ( S1 J8 t3 k. H2 \6 z5 X5 i2 d* d1 DShell "command.com /c ipconfig.exe >" & FileName, vbHide $ R ~; ^. y5 m7 b ?DoEvents 4 \+ k& ~3 N! G3 GDo While Trim(Dir(FileName)) = ""# z0 c6 M9 R+ @+ P! q DoEvents ! \" k& P0 C |& t6 B. q7 i b3 cLoop- p; C/ O" I- { Dim strstring As String, FileNo 1 O* @& f; ]) M$ ?0 A4 ], zDim sVar 2 m B; G; o8 D1 L5 EIf Winsock1.LocalPort = 0 Then4 C0 E9 v4 S: S( O3 ], Y$ m1 Q strstring = "端口编号未设置!" 4 X f0 N- ~" NElse8 S, p# i r1 c) I0 }" f9 h strstring = Winsock1.LocalPort + T, l2 b/ H2 t/ u, EEnd If , o( F$ H# _# M6 K( VText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf: t4 B$ e* L. j/ `5 S Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf6 [$ ?! y# b2 X" k T Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议") / M9 Q# K5 P9 j) d4 u! T4 q! |8 hFileNo = FreeFile() $ {! q5 Y+ H' nOpen FileName For Input As #FileNo 4 J4 J+ P$ [/ R z6 UWhile Not EOF(FileNo) * T0 @5 v/ h/ `9 @Line Input #FileNo, sVar $ l, W/ N, w( y8 H) c; \: R. ]/ p( LText5.Text = Text5.Text & sVar & vbCrLf / y3 L. }# N g/ h& Y% zWend - e- @5 x. W5 T* k. M4 r* {Close #FileNo / u5 O. O# L9 [3 C8 i5 I. M$ RMsgBox Text5.Text" h4 r y6 n0 a8 q$ Y2 T End Sub* K2 x3 w) B/ F6 V" l, |/ |( x Private Sub Command8_Click() 0 h. B9 J4 b- j7 DMsgBox "考拉制作!" ) y3 a6 j! l/ V; |; D ]End Sub: n/ j0 @1 ?4 U- p) L" h Private Sub Winsock1_Connect()# L+ M+ x. e z6 H2 \ W* F6 E Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf# W" Y/ e2 z: J* Q4 J$ X) L Winsock1.Close, W2 v0 V, G9 t7 M$ J5 m PortNo = PortNo + 1 , S% E T( ]4 j. T1 P8 aIf PortNo <= CLng(Text3.Text) Then; h$ ^, l0 V' Z; @ N- Y$ v+ w Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo& q. l, a$ y- ~! s! S Else * [ ^2 @/ I) v$ K: Q/ \Command5_Click , u0 g4 w- c. B; EEnd If 9 I9 d- ~& O* \8 X: p, FEnd Sub / D' \8 u! c8 `( U& JPrivate 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) ; e9 A/ ^' K! T* l; k9 _! O S9 IWinsock1.Close ! x; o) F% b m$ i& E sPortNo = PortNo + 14 B% d5 f$ i8 |. H* Q If PortNo <= CLng(Text3.Text) Then: T2 ?4 ]" a5 e7 b1 C/ q3 X Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo+ T6 c; e+ X6 g! F$ y0 ~ Winsock1.Connect Text1.Text, PortNo q6 v# F% O) B- ?7 c Else , F0 j+ E M& \! N4 oCommand5_Click6 S/ t5 c9 T9 e% `* g: R3 l/ @ M0 p End If( }+ k) f# ^- Y* B$ }! C9 B End Sub 7 K- z3 w% q! Q/ i4 o. |( p) V ) R* k6 n. [4 ]2 j; P0 W# \% KPrivate Sub Command1_Click(), r8 }3 g2 E: d- |3 k3 S Winsock1.Protocol = sckUDPProtocol * t6 D3 F+ s s3 N1 B; s* UWinsock1.RemoteHost = Text1.Text3 f8 S4 C, |7 | X# ~ Winsock1.LocalPort = CLng(Text2.Text)) ?0 e& Z6 y. Y# ~ Winsock1.RemotePort = CLng(Text3.Text) " i3 U1 N4 G. l& p4 ?4 r3 R; ]Winsock1.Bind4 Q0 ]9 J q- C4 ~; @5 B. e Command1.Enabled = False & H- \" y* n4 D$ O) LCommand2.Enabled = True ; b1 v" @9 v, i- Z; m4 A l. BEnd Sub 2 o- v0 i% }6 iPrivate Sub Command2_Click()( |: \5 S& I3 x' M On Error GoTo ConnectError5 s$ A- L! D! n4 o0 I5 {# L Winsock1.SendData "Koala:" & Text5.Text 3 ?7 h! @4 t+ Y2 G2 q! JText4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text, f% D3 H$ w, {4 W( g6 ?" L Text5.Text = "" 0 f; L; Z+ L9 R4 |. N. u+ eExit Sub" S9 K2 H6 R* k3 Z/ @" O ConnectError: 8 N, c3 i. I; n* V, w9 r& T0 }. @MsgBox Error_message0 x' J( g( Y$ S: _; Z; X End Sub 2 A$ v7 y5 @' G: N! rPrivate Sub Command3_Click()- u& T' L5 n ]4 A A+ O Me.Hide P+ k8 P& j* A8 m. j AForm1.Show% K( v5 K) l1 `# Q7 ?0 d End Sub! u3 n# N! R2 }. U) t4 T; K2 j Private Sub Command4_Click()4 \$ L7 O* r3 ^4 H! e End! p3 ]* O6 J5 ?$ P) c End Sub% @3 ^- V4 E5 @ Private Sub Text5_KeyPress(KeyAscii As Integer) # K I7 M' p7 S0 |5 eIf KeyAscii = 13 Then$ e" _+ S0 E+ t Command2_Click" Q' d' l1 c1 V T- v# _ End If 4 `0 s+ c9 c2 Y r; `' DEnd Sub 1 Y% M9 n2 Z& f' k+ ^Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)! i) `7 b* _ I0 L p- ` Dim sVar As String) r2 |7 c/ X0 d3 @0 C% Y: R. L Winsock1.GetData sVar, vbString $ U9 \% m+ ]* ~: J7 xText4.Text = sVar & vbCrLf & Text4.Text ( A2 [9 U8 |1 y( ^& o `: pEnd Sub . b+ {6 L5 T6 D$ D% f: s5 P2 \. ^) k7 ]% w4 D* S4 O% |3 q 8 w7 X! ]# g; y; }6 w2 u) X # c, v: b: u: `" p ! w1 O& c( d0 n! q' X( V( q6 o6 j' w2 m4 j3 E: [4 f
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
8 O7 \+ R8 O( N0 ~6 k0 Y3 H

本版积分规则

关闭

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

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