下沙论坛

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

用新浪微博连接

一步搞定

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……& }. ]( u2 K& N7 K0 f) J# v
请点这里下载  F: R; P( w" x3 o* y; k
恩啊……先打开后保存……
) V3 l0 A- N; r1 u+ E8 V- k5 o% |7 G; ]! F3 Y9 `" z- D( a5 e

$ |) D+ d7 R) y+ ?
/ Q( Y8 q3 I0 T3 f; c+ ?
: j& c" Z, o: c( k/ U8 _8 E6 c! h( e4 B3 m
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
5 ]3 g3 I; ]6 L: k3 ?8 p5 }/ N3 }
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩 转发到微博

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long 1 w7 R r1 o7 Z8 |* Q2 x: z6 C7 VPrivate Sub Command1_Click() - Y4 {1 r4 w+ j9 pMsgBox "您的IP地址是:" & Winsock1.LocalIP 9 {9 K, Y$ m' k/ P+ s3 xEnd Sub 3 W) D; w# t4 V$ s, JPrivate Sub Command2_Click() 3 T! x2 ?( A- g5 c9 \MsgBox "您的计算机名称是:" & Winsock1.LocalHostName4 ~ w7 r1 H, @3 | End Sub 4 a7 K* U1 a6 v' h i' x$ c5 l7 J uPrivate Sub Command3_Click() : }! U% C1 e: ]% S# dEnd) n) Z5 b) _$ h9 R4 b% E+ ? End Sub8 e; F/ q% h* T# i3 d Private Sub Command4_Click()( J) o, A8 C2 \. ~( E, A7 |. F2 G PortNo = CLng(Text2.Text) - 1 % ~% w; I/ N+ i) Z9 V0 k- uText4.Text = "" 9 [2 x% V `, Z$ kCommand5.Enabled = True4 F% Z* q& L4 [$ J Command4.Enabled = False ) R$ C' ?/ x; v/ J( F7 TIf PortNo < 0 Or PortNo > 32767 Then ; {; T0 p, v2 SMsgBox "您的输入错误,端口超过范围": o( K7 c5 `# _( d- [$ x Command5_Click " H- U2 w7 ?8 a- |' |* ~% |7 LExit Sub 4 u: N' Z$ E& O& C! jElse ( f& H8 [% `. d5 X2 UWinsock1.Connect Text1.Text, PortNo; t* q; p3 k) L, J( e/ L& ]7 U3 }3 _ Text4.Text = "开始端口扫描......", g+ D& l4 T6 s' X$ h End If : y4 J6 ?8 X7 rEnd Sub " b" ^- j+ Y1 cPrivate Sub Command5_Click() . H, O: b9 M- w) tCommand5.Enabled = False + m2 W# k9 o( w$ ] _1 |4 }Command4.Enabled = True! K* c% r- G! @( c. _4 s, R Winsock1.Close 7 m* N# ]- G0 N) _0 d% v+ Q/ BText4.Text = Text4.Text & vbCrLf & "端口扫描已停止。". I, J/ c: ~" N6 a: e" m End Sub2 b% Z3 F! T& T Private Sub Command6_Click() $ l* O. H' t9 V* z8 S% X5 GMe.Hide5 P4 q" |/ M- l: g Form2.Show/ y7 P. N$ n, c$ U @+ J End Sub) K: e `7 H3 h& I+ x E Private Sub Command7_Click() 8 u' ?1 y0 V: l v; `FileName = "d:\ipdetail.txt" 5 x% K1 A, d" K# hShell "command.com /c ipconfig.exe >" & FileName, vbHide ( V6 m3 A! S, iDoEvents2 n( @5 a% _6 Q% t8 `" h, X- u4 { Do While Trim(Dir(FileName)) = "" 5 @8 C( L% L6 W& ^3 i, cDoEvents 4 F! F8 }3 o* U" S3 CLoop6 N* k- K r: p Dim strstring As String, FileNo 6 |. Y7 u( R3 n) IDim sVar l+ ?( Y4 Z0 f x# P' R8 W4 |If Winsock1.LocalPort = 0 Then 3 _+ Y* V9 ]( ~6 @9 u; u0 t2 Ystrstring = "端口编号未设置!" / P: P' n( W8 p6 ]4 GElse- ^8 I$ l3 H/ h* Z1 z strstring = Winsock1.LocalPort* V4 ?# ~* y3 g$ I# I' w End If 4 w9 c9 B: v WText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf/ L2 G" m9 [5 k Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf/ w! g$ G) \' T( \3 | Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")# `9 o' `7 N( b0 c( z FileNo = FreeFile() F Q; e$ o* G& m5 l4 r, G% t: VOpen FileName For Input As #FileNo 1 X' M: ^+ z* g# M: KWhile Not EOF(FileNo) # x! Z3 `. q1 w! zLine Input #FileNo, sVar ! ~$ |# Z5 H. vText5.Text = Text5.Text & sVar & vbCrLf 8 A8 \/ q/ y0 \0 eWend, n: F& V" Y% Q& S Close #FileNo ' l1 k3 U8 @% n$ gMsgBox Text5.Text3 {, T. ?$ n3 g- `& L: N7 t! `1 w End Sub: D$ S1 ?. E7 Q Private Sub Command8_Click()8 C, G; b! m7 b+ S9 A' f MsgBox "考拉制作!". H1 ~( W) Y7 U. A End Sub" a5 u6 |9 R" Z" N- |) ^$ x Private Sub Winsock1_Connect() 4 C- \/ U5 J& {$ L* YText4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf- U2 A# U( E9 I9 v2 q Winsock1.Close & ^3 l- k n. Z' q% E. k/ JPortNo = PortNo + 1 q6 w- |! z9 q; F% k If PortNo <= CLng(Text3.Text) Then 3 o; }; [0 Y9 H0 _- P5 UText4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo ; _ a2 ^! v# V# T; `. OElse # f$ }( L0 W/ z3 CCommand5_Click& _9 X) D. X( j$ k3 j: \9 ] End If + }/ B% z `4 L) n4 x5 g9 i' }End Sub # W7 S7 }2 t: CPrivate 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) $ u5 e8 p0 B2 C# z4 w6 LWinsock1.Close 0 P9 y1 Y3 t0 s0 a8 y6 j2 z/ K4 F: mPortNo = PortNo + 1; ~& m V- x: B0 {8 i- _: y If PortNo <= CLng(Text3.Text) Then' Q3 C( r: R# w& M: a Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo$ W' \, x: w- s) O4 G! G4 U Winsock1.Connect Text1.Text, PortNo2 g$ f( [2 E& k* l/ N1 \+ Q Else 8 B( o2 h2 T/ BCommand5_Click 8 {0 M6 E0 c- Y' Z+ q" O; s( o$ zEnd If - u4 V$ N/ E8 pEnd Sub * B# y" F, A4 x i ! l# C& C6 ^& \( QPrivate Sub Command1_Click()! v2 |2 A( S4 ]0 m8 j Winsock1.Protocol = sckUDPProtocol& A j$ W* U+ C% R! s9 I Winsock1.RemoteHost = Text1.Text! g% |8 O. s0 J7 m Winsock1.LocalPort = CLng(Text2.Text)% T! j B; U3 \) H) u# s Winsock1.RemotePort = CLng(Text3.Text) m8 ?7 o" P- b# K6 [& ~$ JWinsock1.Bind ) H; T) p [1 e. \$ OCommand1.Enabled = False4 v h/ N" L& V Command2.Enabled = True 3 W B" @2 n; M& [ a) L/ BEnd Sub 8 B5 b6 ]7 i8 VPrivate Sub Command2_Click()6 R% @8 T5 ]( |7 d/ w4 _/ u' W On Error GoTo ConnectError6 K# g8 ~' [2 P Winsock1.SendData "Koala:" & Text5.Text y( v, z9 W( y% T7 B/ y' {Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text B1 z5 U& E" B. k) X0 N Text5.Text = "". V/ q3 o: ]9 g9 a Exit Sub 0 w' U' L3 r' B! n4 tConnectError:" [0 {) D/ u/ |8 q" Q1 F- @ MsgBox Error_message9 o1 @8 b$ A7 I, Q6 H; A End Sub 3 t, P: U4 t9 l8 aPrivate Sub Command3_Click()0 H. _( U- Q2 S3 c; b Me.Hide 5 I% G L+ p0 _8 i4 h- Z. e4 MForm1.Show & ^% k$ w; i* P# e' YEnd Sub 8 `; _" u( O/ k7 v8 ]Private Sub Command4_Click() 7 k' }- Q. Y+ Q3 g) JEnd - x! b y) D; j8 }9 u0 OEnd Sub % ~+ U, s& `. g) ]5 i8 v6 N* aPrivate Sub Text5_KeyPress(KeyAscii As Integer)& E4 a9 x: N1 M9 @+ d T If KeyAscii = 13 Then1 [2 v: z$ f# \; W Command2_Click/ U) B' O! Y" n" D5 A: u0 P; h End If6 [: D/ p# G- l$ s End Sub: q/ v- F7 s7 t) j4 _ Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)1 ` g6 s* A0 R8 o5 y7 a+ c Dim sVar As String " l8 O& W8 B* |; M# K% ~# y8 ?Winsock1.GetData sVar, vbString 1 K8 Q& T1 y6 q2 G# C9 R2 [Text4.Text = sVar & vbCrLf & Text4.Text9 g, r' l( P/ g1 e End Sub 5 [) G' g* q1 J" `: T& k* Q& [. a8 A1 H% J2 E/ f0 h3 ^* y 8 I6 j# J }; e9 T% R % n. u' Q. o, h3 X% V( o$ G 7 t5 u4 J. v# `3 F9 B5 ?6 D2 m H3 _% V3 u
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
% ]) w* I" ^1 x0 \' n9 ?

本版积分规则

关闭

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

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