下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……' Y5 K  Y! P4 ?% u
请点这里下载5 K" |. j4 f7 \0 ~! i
恩啊……先打开后保存……, }  V* h, w1 O! D8 @
  j/ d8 {  W$ J  w& V$ M+ x

- u0 l  m4 p- C. K( `
7 l& n' T7 O6 {3 X' M! @. k0 Y2 `
7 I/ R+ c  K' W3 p
[此贴子已经被作者于2004-5-12 20:15:18编辑过]

( b; V* J0 [. W: I- _. o& a8 L
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long 9 w% z, i* o6 t5 H% x& t7 tPrivate Sub Command1_Click()" k/ s3 y# n6 \. J; Q6 |% T ` MsgBox "您的IP地址是:" & Winsock1.LocalIP / k" |! K: }; N1 } A2 K* W. zEnd Sub + Y- V; Z" H, H' qPrivate Sub Command2_Click() + a7 R: S. Y8 f; \( e9 k3 d3 v& HMsgBox "您的计算机名称是:" & Winsock1.LocalHostName/ {+ E9 X2 x5 A End Sub . h- t" \! I! `8 ^9 u& E1 I. hPrivate Sub Command3_Click() 6 m- g3 r" M& ~* `( PEnd; E5 a* f1 U T( p! H3 o' i: ] End Sub! \8 g. H5 |) [2 B/ S4 h Private Sub Command4_Click() 8 c9 w7 M" \0 U+ CPortNo = CLng(Text2.Text) - 1 6 n: ]( d5 v6 Y! {% ?4 B. TText4.Text = "": s! C0 V2 A* Z x. F3 M Command5.Enabled = True6 j( a, b4 g- }3 z5 b6 W% F Command4.Enabled = False : U# N" U2 z7 h9 U4 F/ n2 o% FIf PortNo < 0 Or PortNo > 32767 Then . p6 i' H# z) X: r+ ?MsgBox "您的输入错误,端口超过范围"4 U6 ]9 {+ s' m2 K3 W# X Command5_Click: w8 I( y# \5 q. a4 ? Exit Sub' e" N7 A) e% k5 {. O: A* X9 y Else& `$ {9 k0 [% G" @/ L. v Winsock1.Connect Text1.Text, PortNo % v7 R+ ?! @. u7 L9 E6 @Text4.Text = "开始端口扫描......" # W9 R5 Q# Y+ pEnd If6 J' j' u d/ M5 q+ G& I End Sub $ C4 [( s5 H) y8 ]Private Sub Command5_Click() - b4 b( f7 a F* sCommand5.Enabled = False 7 Y( B0 L: d0 m! }Command4.Enabled = True% t$ r- \5 u9 M Winsock1.Close * f8 M$ t4 S4 G, ^: {5 MText4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" 7 [- J# A1 _( N" u* j2 B6 [) [End Sub J) y5 X6 x$ g E- d1 S g" o Private Sub Command6_Click() + x* s6 \7 J+ W' M% yMe.Hide 1 L" @0 s% K- B+ pForm2.Show G2 M1 [5 H- O3 ~0 q7 z! M End Sub! S8 {2 ]; E& |. Q Private Sub Command7_Click()8 i" Z* O) [4 E FileName = "d:\ipdetail.txt" . @" n j: m r' q7 N4 OShell "command.com /c ipconfig.exe >" & FileName, vbHide! q! P+ e- K* S3 N8 e( ?, O0 v' ~ DoEvents ]7 g& t- J7 }& MDo While Trim(Dir(FileName)) = ""+ N& C9 j L# F* I9 y DoEvents $ Q' D Z" d4 P9 K8 j+ G$ o( lLoop/ J- U7 }5 j0 H0 {) v, L0 F Dim strstring As String, FileNo + }: i8 I9 ?$ h D/ [. q iDim sVar; M9 Y* G5 p9 m. Y If Winsock1.LocalPort = 0 Then : V$ Y6 T% L1 H& Wstrstring = "端口编号未设置!"; S/ t& Y" n1 z( _3 M Else& C3 \& r; U% T% v& M' L strstring = Winsock1.LocalPort ' ]# [2 D' ]0 P9 S- k% MEnd If 0 T1 y5 L9 C1 w# {# W! AText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf! d4 x' X3 e* S5 v2 _. F ]# {7 P Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf % j2 k3 F# O$ b3 x" CText5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议") % P" ^- a5 m! ^+ C2 YFileNo = FreeFile()$ h, A6 F6 f/ a6 |0 K Open FileName For Input As #FileNo ; |# x3 s3 X8 oWhile Not EOF(FileNo)% y9 [& D7 j7 F Line Input #FileNo, sVar z) }2 y! _% k: p Text5.Text = Text5.Text & sVar & vbCrLf) N' I1 {& M& {- J: u7 T Wend ; J4 c) B* v, G( d9 w$ t$ WClose #FileNo9 Z9 d- Y/ X& z% \ MsgBox Text5.Text ' O9 w% K/ F+ ]+ l: r3 M! YEnd Sub 3 p) r' ]" a2 t8 APrivate Sub Command8_Click() 5 L+ E6 |% @9 ~3 U7 ?+ B/ a! eMsgBox "考拉制作!"- B( Z Z, e/ Q; ? End Sub# b9 Q8 D) P$ S' W Private Sub Winsock1_Connect()9 ~! }: P# p: g/ b( `* ~ Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf2 e% l. n" U8 D' ]% d f* n7 s& e Winsock1.Close8 U r9 a. X6 d2 k) S PortNo = PortNo + 1 ) H- K0 Y9 T' I% b2 O( nIf PortNo <= CLng(Text3.Text) Then # _( J5 g8 r( @: \& \& H1 EText4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo 5 N9 q/ i* F% L5 Q+ a) yElse4 t2 @0 w8 T7 l, c6 s: I: G; d9 d Command5_Click - [) j) A; R$ }( Q: ~" k3 q. LEnd If 3 `' y) R2 Q6 b3 w; j+ HEnd Sub 1 }3 _4 N5 j' h9 p; vPrivate 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)$ S- {1 x `- c' \4 N2 U: Q Winsock1.Close * _5 \4 g0 [5 D- P" o: e2 }' qPortNo = PortNo + 1 ( ]( s) I, H( n! [/ HIf PortNo <= CLng(Text3.Text) Then- z/ n& r$ G9 s5 p Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo$ k- N5 l. p, p Winsock1.Connect Text1.Text, PortNo' f- Y4 Z; L* y4 \ Else v* k' ]% \: y5 KCommand5_Click0 p- f [2 e% w$ _8 ~5 ` End If2 H$ u& l0 ~6 D3 y' T+ T End Sub. H, j0 Y+ ~0 O : R5 a8 m, J9 M a( xPrivate Sub Command1_Click(): Q0 x- d, j) Y. D1 o# H Winsock1.Protocol = sckUDPProtocol 8 t7 M, G6 ~- z) D" vWinsock1.RemoteHost = Text1.Text6 b4 g( _. ^! L. G4 _ Winsock1.LocalPort = CLng(Text2.Text) 1 X, f/ H! i0 q p, d4 Q' L4 E3 sWinsock1.RemotePort = CLng(Text3.Text) ) H/ K8 @/ a1 t# O2 d% ~. NWinsock1.Bind( W3 }- C/ B4 k( f& w Command1.Enabled = False3 K% g1 K1 q6 {* p Command2.Enabled = True; B" g; q, }7 l End Sub, Y) j( K& K! | Private Sub Command2_Click() + f2 ` g ]% J; f: M4 HOn Error GoTo ConnectError3 f- ^- ~( w5 v4 i/ {& A+ }" \+ ]/ q Winsock1.SendData "Koala:" & Text5.Text ) n' Y% A! [) B. u H9 ]" X! B ^Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text* B1 b# ~- L9 {& h: C1 s Text5.Text = "" ( G6 O1 @5 f+ iExit Sub! n6 w6 o7 [: [% `3 ?# Y7 A ConnectError: * n; V: y; n) I, gMsgBox Error_message ! X2 ?( f/ W% ~3 \5 pEnd Sub2 h+ b6 g) T; o; t Private Sub Command3_Click() - Z! f: p9 K2 w5 T! z& W: h7 Z( pMe.Hide( O" \3 E$ v7 ?( N& E( m Form1.Show " z6 U1 H+ g% H1 z# T; J) `+ sEnd Sub 7 ]5 N9 D( z) s8 k- QPrivate Sub Command4_Click() 6 Q; y+ j8 }2 V1 N1 a$ N) JEnd ( G0 y4 H, f" }1 K7 ?5 ?1 y4 N" u( i/ aEnd Sub8 |% w. `. o( ]$ A5 N Private Sub Text5_KeyPress(KeyAscii As Integer)% M8 {0 Z; u! O. L5 Q% M If KeyAscii = 13 Then- A+ Y- d& @( D4 x" M Command2_Click+ K$ Q; h; ?! e7 f* @1 S End If4 U/ u5 p( S. h' r7 s( ~. W End Sub 9 K. M8 y# @2 F, g5 hPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long)! n, P% w2 l- S Dim sVar As String ( y7 o( b1 m8 A7 ~/ m% y# G$ xWinsock1.GetData sVar, vbString $ j: v' R4 `6 Z; JText4.Text = sVar & vbCrLf & Text4.Text; K+ o9 ^4 j( T: W- F5 m End Sub 0 |, _8 t1 g8 A' v0 G# u( |2 V" }7 z. a. y8 F& \ 2 ]! C# H, S2 X$ C # E5 ?6 g+ t; h3 v# C ; A" v% D& X3 z$ v2 B$ i , W1 j2 d K4 Z5 U8 f5 O N k
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
. V& p" T* ~8 m5 ~0 e

本版积分规则

关闭

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

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