下沙论坛

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

用新浪微博连接

一步搞定

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……
7 O: z/ N  P* G- n, D7 N: A请点这里下载! |3 a% y+ W+ Z3 ?: i8 F
恩啊……先打开后保存……8 ?  q2 H5 N2 O4 ?7 U

; I  d5 o1 `1 Y5 m. X. G2 v+ ]: h. B! q% Z5 u+ P! S! z
+ y% O+ W0 q+ j

  c+ x7 p9 ^: o+ o
% k4 K& t: q9 E6 J. n$ {8 V
[此贴子已经被作者于2004-5-12 20:15:18编辑过]

. o. {- Y3 y0 z  I
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩 转发到微博

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long) `( U9 y* @5 ~0 g- N) s Private Sub Command1_Click() * f; e" m+ j; b2 f9 I) [3 H! mMsgBox "您的IP地址是:" & Winsock1.LocalIP - X9 R" I4 X5 k( m5 o1 f. u" u8 AEnd Sub : o2 q. K3 F9 }1 G& f# l- aPrivate Sub Command2_Click()- F! T; i0 m2 k8 ^& F MsgBox "您的计算机名称是:" & Winsock1.LocalHostName! m* ?+ m" H; p; ^0 d1 q7 q% Q End Sub8 k) q3 G- Z/ d Private Sub Command3_Click(); _9 R0 Q' I$ K End , T | p/ r2 ^4 UEnd Sub$ W& ]) t% ?9 g$ R Private Sub Command4_Click() m( y, Y3 D m' W% O7 yPortNo = CLng(Text2.Text) - 1' a! o, _1 i' y+ T9 E/ ` Text4.Text = ""3 o3 [+ O& n+ E1 z5 Q: D- I: N Command5.Enabled = True , B3 m) _) @7 W3 ]* u) s0 MCommand4.Enabled = False( v/ ^# b* Y9 k+ P If PortNo < 0 Or PortNo > 32767 Then: T0 Z9 V8 a& _6 Y5 _+ F8 F. C6 y/ F j5 D MsgBox "您的输入错误,端口超过范围" 6 w! W a$ W: U! j( L2 m! kCommand5_Click 0 h! t/ Z5 ^. L# | t' ]Exit Sub $ F. I- G1 a% {4 SElse 0 e, D9 z& n# o$ [ {Winsock1.Connect Text1.Text, PortNo2 w$ K+ _* O+ F; X; L Text4.Text = "开始端口扫描......" ( G+ g+ ?# _3 s* G+ O4 j6 fEnd If0 {8 q7 T _; I% `& v End Sub 6 G/ D, Y& z' P5 X, b, p% Q$ lPrivate Sub Command5_Click() k0 Z5 |4 F3 |( d1 Z! R; n Command5.Enabled = False2 o3 h, c* m: S, ^: b Command4.Enabled = True8 ?' l* Q: G! ~6 i+ L Winsock1.Close . @. Q( _0 a, g' B/ W- @: jText4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" , H5 u+ z( K) T" W3 Y- \End Sub6 h+ F' \6 r; `9 T6 E Private Sub Command6_Click() $ i8 F/ ~8 Y: D8 }9 H9 iMe.Hide. ]( m& J6 g+ w' b6 f4 }$ @- X Form2.Show * N8 S: G% Q: T FEnd Sub4 W: n0 b7 Q' n, r: @4 p: o Private Sub Command7_Click()/ Q8 Y- l _. K) ? w4 o! q3 o% l FileName = "d:\ipdetail.txt" 5 x* b4 p3 G1 D7 N3 A3 D% }% f2 W6 TShell "command.com /c ipconfig.exe >" & FileName, vbHide 0 G x2 j8 O+ I, @DoEvents 6 s/ v1 g& ^4 w# ^0 }: L' a5 `, |Do While Trim(Dir(FileName)) = ""9 W8 {/ G. M+ P DoEvents& v8 Q- K; M4 F Loop3 N# r6 L1 B2 J Dim strstring As String, FileNo9 [+ H3 A5 L/ y8 Z Dim sVar 3 w1 v5 H- G5 \! }If Winsock1.LocalPort = 0 Then7 }9 |& w' |" z strstring = "端口编号未设置!"- a! O0 q# s- D Else : ]5 Q2 R" p0 p L& `* m6 k! h4 qstrstring = Winsock1.LocalPort: I6 a" n4 t5 f" C0 J- f1 q5 S5 C+ @ End If 5 T8 R# v0 x' K3 oText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf 7 ]" n( r% W# b |! m. ]1 rText5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf & k) p, p; k8 P: J& DText5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议"). F* D2 X+ f7 m" u/ u. g FileNo = FreeFile() % @7 @$ z( P/ [, S; g! a. xOpen FileName For Input As #FileNo : n' w1 {6 x( `9 o9 F3 I$ kWhile Not EOF(FileNo) . G& w4 n& @0 q; n' SLine Input #FileNo, sVar( R: R c+ I* J K8 ?8 m$ X" r Text5.Text = Text5.Text & sVar & vbCrLf, C! q# |4 r6 S L Wend / Q, G! q3 b3 B* }( y1 jClose #FileNo. r! U* a0 h. i4 @/ e) k MsgBox Text5.Text( D" w0 f2 O7 |1 d3 y5 O) K End Sub 3 s% Y, [' H9 WPrivate Sub Command8_Click()7 X3 {8 o' _8 E& e @ MsgBox "考拉制作!"" A0 C2 u! \! T5 n6 E- i9 q4 v) ^ End Sub1 W6 X) f) e7 D* x h: Y Private Sub Winsock1_Connect()( M4 U; f. z$ a1 c, Q1 i Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf! c, c ?7 y9 {9 g! L) g Winsock1.Close 8 c! {0 a6 F6 S7 s! oPortNo = PortNo + 1! ]! x$ c g1 {8 n If PortNo <= CLng(Text3.Text) Then: e! K2 H/ ?0 T" S& T+ L Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo I% O3 f2 T \+ y Else5 I0 o% W+ E! M6 i) ~ Command5_Click8 j$ T+ Q" X2 m$ q. y End If$ K7 s! x0 f- p0 H7 C- s* H End Sub ( ]# `% Z: D" n1 g* WPrivate 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) 9 H9 r( @% X9 X* P0 Z2 aWinsock1.Close p6 T$ e x& Z3 b/ R, v PortNo = PortNo + 15 L) I/ \* C# l! ]$ K6 N If PortNo <= CLng(Text3.Text) Then7 ]* }9 ]; U) Q! j2 U Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo / A1 D9 E8 v4 \Winsock1.Connect Text1.Text, PortNo 1 ?: t& H/ n+ Y! sElse; e3 A+ n( d2 m% S) X% X, s Command5_Click3 N5 _* `! L: m/ y$ }# ? End If/ L% y% @* A. s* l- i% }% u: I End Sub 4 T0 l% t$ z! O, @. d4 Z+ @* E* x, @8 v/ S Private Sub Command1_Click() 1 \3 A: K0 A& A* fWinsock1.Protocol = sckUDPProtocol/ \! R/ z! V4 u6 N/ V d Winsock1.RemoteHost = Text1.Text 8 `9 ?# g1 ~# {9 c0 ~6 F, C& KWinsock1.LocalPort = CLng(Text2.Text) 5 r, J4 S; `% V: EWinsock1.RemotePort = CLng(Text3.Text)+ l" I( d0 s$ A2 y O Winsock1.Bind : G# D: N+ n" @6 {0 S. h7 pCommand1.Enabled = False( \+ q; o0 m3 m2 @7 v Command2.Enabled = True 5 A F- a: I: G1 BEnd Sub3 N4 V* M1 b& L0 i/ n Private Sub Command2_Click() 2 H8 d% v/ |. k$ H% v" wOn Error GoTo ConnectError 0 D+ q1 K; @ G' eWinsock1.SendData "Koala:" & Text5.Text ) P9 {5 e: R8 EText4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text % J4 A8 Z$ ~0 LText5.Text = "" / I" q- n: c6 }Exit Sub2 ]9 U; l( w8 J3 f0 p. [ ConnectError: + \9 r3 |; X, P8 JMsgBox Error_message ' R) k6 d+ E$ R @- {& ~8 gEnd Sub$ s3 E/ g @! R( \2 _ Private Sub Command3_Click()0 i% @9 C0 q- O Me.Hide 4 B$ [3 e; z B/ l" B x5 _0 V1 h6 MForm1.Show 1 N; i: z2 d9 k- a6 i' O; Z1 } @End Sub% J# t+ C5 `* Y* l! z Private Sub Command4_Click()8 I) [+ M1 U3 o9 }- E$ \2 _+ J End; w4 O5 T* o v J End Sub- L- g& y. E! q Private Sub Text5_KeyPress(KeyAscii As Integer) % [7 B. w$ L+ d8 s( ?. \If KeyAscii = 13 Then . z, J! @# R3 I6 ~( BCommand2_Click H h! I8 t/ W% q, J" _End If . C$ z; R4 A! ^7 a% ^End Sub * z6 \7 s7 {2 I% w8 N; v( {Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) ) S+ q$ o3 d. U. sDim sVar As String3 i0 J, U8 g+ V: y7 Q8 ^) \ Winsock1.GetData sVar, vbString: e/ S) i- r$ t) ^# o9 \% n' D Text4.Text = sVar & vbCrLf & Text4.Text; ^ Y2 d2 m/ n8 K3 q End Sub 6 h0 B9 _1 ]7 j 7 ~ L, h" b) w. l* \% i1 I3 @6 Q% H . b/ C* \4 o. U& u* y4 _* ?- r 4 K2 ?8 A6 v4 ?; i3 z) T 3 N8 h$ z% T' F4 ?1 z) o& Z
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
- X! S, k1 l& L

本版积分规则

关闭

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

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