下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……
# i2 O; }; N/ V+ O- Q6 ]7 w# i请点这里下载& L0 e9 X8 n7 u) v$ m
恩啊……先打开后保存……+ h( y5 t7 r$ @/ n2 ~* m& s
% G8 K, L5 X" S

. y4 ^' k. N" H+ V0 F0 a
- ]+ k6 W, g. e# c6 x$ o5 H
' Q2 a- }# f1 J% o# N* p, N2 A$ x  u0 g) A: \% @. ]7 C- {
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
  p0 h5 g! f! b; |, W4 X6 D% f
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long ) Y+ P- s" q ZPrivate Sub Command1_Click() ; s# I/ o5 d( r% NMsgBox "您的IP地址是:" & Winsock1.LocalIP; Z9 Q( _. h/ ?1 `+ j End Sub4 ^( y- y' S6 Y n+ l8 w Private Sub Command2_Click() , C) H! b% M% b4 w& ?2 G; m: d! VMsgBox "您的计算机名称是:" & Winsock1.LocalHostName( I1 ]( ]" f& m2 e End Sub / w2 J1 N- O) q3 |& D8 SPrivate Sub Command3_Click(). o5 {& o6 e6 [: m. I- q# W! G: P End 6 r* S4 `5 L) @7 q( sEnd Sub1 Y% w: |) o8 p7 e3 e6 ]$ L7 B Private Sub Command4_Click() - I4 p: M7 f5 y5 RPortNo = CLng(Text2.Text) - 1 : H' f2 N1 X8 |# x$ ^1 o' VText4.Text = ""7 w' @0 c- R3 L. ]2 ?6 t: H) G1 C! S Command5.Enabled = True 6 M4 S) v% D5 r* B' s3 g/ g2 Z3 vCommand4.Enabled = False3 m" V1 ^) f( G2 g. e1 N If PortNo < 0 Or PortNo > 32767 Then, Q) c! `; K5 q! A% @5 `) o4 _" u MsgBox "您的输入错误,端口超过范围" ( D( q9 i7 T) F6 x) }) c- k6 fCommand5_Click; t8 v5 k2 @! k" U: P Exit Sub $ I8 p& n/ P5 }3 ?. UElse 2 K3 P; `( H3 TWinsock1.Connect Text1.Text, PortNo ) I+ b" f, z8 B4 V. gText4.Text = "开始端口扫描......" 1 E5 O) V. l* s3 D+ Z. ZEnd If8 l* i$ ?" \% R( c# ]* ^ End Sub / B: I8 n; u0 \! N3 O l W9 uPrivate Sub Command5_Click(), W# a2 x. p3 X- B3 r Command5.Enabled = False ; u& u. W! l9 g7 ^# {: iCommand4.Enabled = True4 h9 V; M0 ?$ O C Winsock1.Close$ J0 P$ S/ a$ h" n* ^ Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。"2 q: D. H/ z9 { End Sub 3 v; Z _7 E" Z0 [ WPrivate Sub Command6_Click() * r0 M) z7 ]+ I4 KMe.Hide 1 Y3 _0 F$ u7 G1 bForm2.Show% ?" i0 _2 j0 L, @# g% k) { End Sub6 p3 |8 M; q/ F! p& C- K Private Sub Command7_Click() 5 w5 y4 ^% ?9 a$ l; dFileName = "d:\ipdetail.txt" : k. P& v2 T1 K0 zShell "command.com /c ipconfig.exe >" & FileName, vbHide& ~- I3 h% B8 p( A( k DoEvents 1 v) p4 G* t1 l/ tDo While Trim(Dir(FileName)) = "" , Q- T6 C; B4 _) F: u# E: c: t7 DDoEvents5 r- a8 E( m. A Loop9 V& d* B; V7 F Dim strstring As String, FileNo( c3 T5 l6 m5 M0 n' t+ g Dim sVar) j" r! X3 K4 C0 \1 O4 b9 T+ U If Winsock1.LocalPort = 0 Then ; I3 W+ f$ {; A5 b, k- }4 ?, Jstrstring = "端口编号未设置!"- H9 |0 e; {; l; j) u( \" w* X; _ Else$ R+ w3 G( q8 B1 I6 V: ^9 X strstring = Winsock1.LocalPort4 p9 U" @# b$ D End If ; @' i3 _$ o" H( s" M9 BText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf3 ]( T7 V; x8 \( Q( ? Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf ! u. F+ f+ |% j; Q" SText5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")+ g: N8 ?; c8 h2 D* i FileNo = FreeFile()7 g1 Q+ n2 Z. h3 B' A Open FileName For Input As #FileNo. w1 M: w' l; ^3 _! I While Not EOF(FileNo) " ]) b7 f1 K/ Y+ [: d( zLine Input #FileNo, sVar , _1 p$ j5 m- x; a4 H& N2 I; x( i( K/ ]Text5.Text = Text5.Text & sVar & vbCrLf2 @' `# |0 v0 O# E0 B( p; H0 d Wend3 ~3 P3 R& D# ^- \% g- x; Y Close #FileNo$ W0 z4 _: ~$ P+ b MsgBox Text5.Text . k5 o i2 p/ eEnd Sub 6 s7 F% Q( p8 K; _Private Sub Command8_Click(): F3 ~5 O3 r: Q! B( y MsgBox "考拉制作!" 4 Q' H5 | b9 @, ?* _, w. w8 K0 [End Sub/ p5 Z6 n, d. X, @. ^ o Private Sub Winsock1_Connect() M2 d8 V1 x* C) NText4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf+ z6 K0 u# d3 U* |9 w+ w Winsock1.Close 9 L) {& t9 ]/ @0 E" P; ~' ePortNo = PortNo + 1 ; I6 J) Y4 T( R) t9 c/ c2 @# Q9 ZIf PortNo <= CLng(Text3.Text) Then6 e( M( C$ m7 F) i0 P' r Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo0 @# j/ q1 E* I6 m Else- j) E! n1 Y' r- p8 z& d0 S Command5_Click3 q/ A: }6 Y( u- Z End If / ]( e8 l- ]! f) Q3 zEnd Sub ( ]: P/ j$ C: H) P+ C" oPrivate 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)& B1 P% K& n8 m: e4 F Winsock1.Close 7 f& P* d6 K% I# S* M, k3 wPortNo = PortNo + 1* }2 }5 R; {2 Z+ {' m If PortNo <= CLng(Text3.Text) Then1 n; E$ J$ f8 }5 B Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo . \$ p* B6 `: O5 \' H2 Q$ k" L- EWinsock1.Connect Text1.Text, PortNo - w9 i# o* E, g* O! ~Else 4 `9 I5 C* R5 ]: H( H) QCommand5_Click" x G3 d6 w4 s; [: | End If3 I' h0 |# _) B2 ] End Sub: r1 G8 C7 P8 n C' p' U. v 1 `( p6 H4 Q1 `& z- b Private Sub Command1_Click() ( v X% c/ J' A, f0 VWinsock1.Protocol = sckUDPProtocol * i1 A+ L; k4 }5 `Winsock1.RemoteHost = Text1.Text2 j+ |' h9 G2 t+ r/ O* y- Y Winsock1.LocalPort = CLng(Text2.Text) - O, N( m) S2 s8 S( ]+ QWinsock1.RemotePort = CLng(Text3.Text) * G$ d9 P4 _8 o8 ?; dWinsock1.Bind5 V- \& [1 U9 c6 E) m' @* ] Command1.Enabled = False . q! z, k8 T/ n G, D& iCommand2.Enabled = True 5 n: m' {- L8 ], ^End Sub 6 F! Y" F" t* S7 f3 t$ lPrivate Sub Command2_Click()) O3 `/ P4 W4 ^* P ~6 C On Error GoTo ConnectError 9 I/ c9 E9 R$ d K- I2 c; JWinsock1.SendData "Koala:" & Text5.Text & U: |. r) q; y: f0 J! s# BText4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text * v: b b% V" g; S9 O7 bText5.Text = ""7 `- L6 v! l' Y, L% P" x! ], K, Y Exit Sub: j& F* s3 s! m3 w& k9 R5 C- G3 u1 _ ConnectError: 3 W% F5 G. O' {3 U" u6 qMsgBox Error_message ; G# H) c2 i3 N9 G7 \2 b6 G V( K9 A! ^End Sub 5 @$ Y3 `' w* u( ?9 B4 g9 [Private Sub Command3_Click() ) X0 X4 u5 g/ ~Me.Hide ; {' ~% F4 f7 Y# }1 bForm1.Show c- [" j+ U8 u+ t: m; w6 u8 @End Sub ( ~8 e1 i. k) o' @Private Sub Command4_Click() " }$ ?2 B/ |: |( z6 U9 O, _8 BEnd " ^& j, }% S$ R- {- P7 e$ V% TEnd Sub , P! U; w, U" W1 WPrivate Sub Text5_KeyPress(KeyAscii As Integer) . B8 a7 |6 T+ V/ \: L1 UIf KeyAscii = 13 Then ) H" {1 ~/ z- _. X2 r4 O ~Command2_Click1 p* ^/ {4 o5 `6 m- z6 s End If: w( ^4 R4 @- c3 N$ A End Sub * x3 a3 X( ]7 `. a$ d& _Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Q7 D7 A- h8 O; d5 i8 U+ ? Dim sVar As String 6 E6 ~& L J$ r* ]Winsock1.GetData sVar, vbString " N p9 b9 L( S* {1 o. q5 CText4.Text = sVar & vbCrLf & Text4.Text. T* y( `2 w) t/ U End Sub+ p8 W; c2 B. f $ l* U) A* E# [( [! o3 L- N1 n - H& [8 |+ T& n7 q / b) f: A1 ?! y D8 l3 [ x / U& k: t4 e8 W$ d ) c0 L" V; g$ W' z) L1 k+ K
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
" K. |0 [: X6 Q1 }7 s

本版积分规则

关闭

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

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