下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……7 B+ H3 _1 y  ^4 M
请点这里下载
& Q' @. k, r) I$ J恩啊……先打开后保存……
+ E& n9 O: q7 b: g# i; _
6 U: a) v7 z* s; @; ]& G. P  i  d+ B, F# N" ]" [" V; d
! N. O: B2 C% G2 {8 x

: C# L4 p, d+ Z" |, w; u  n1 V# X) B0 Z! E
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
# o8 ]( v. O1 y+ D; A
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long v J5 x( m9 u5 `' n Private Sub Command1_Click()& X+ n9 B: N8 f0 L/ h. H# Z/ ^ MsgBox "您的IP地址是:" & Winsock1.LocalIP ' S1 p. F2 p/ A0 \2 B$ qEnd Sub ; E J% E( a8 v0 f7 H: X# O3 J3 u# JPrivate Sub Command2_Click()7 s \# O3 w" P# G2 K8 L' ^1 z' H MsgBox "您的计算机名称是:" & Winsock1.LocalHostName ; x6 S0 E( `# S; p; lEnd Sub8 y: N: L- Y" [ Private Sub Command3_Click()" j' C/ v& |; a% S5 N End3 {8 e8 u: ] G- t End Sub ! \ l3 Z, b s; ~1 q' K1 X7 xPrivate Sub Command4_Click() ; q& Q) W1 F) z' o' QPortNo = CLng(Text2.Text) - 1' ~/ G7 y$ o$ a Text4.Text = ""6 g2 I3 Z9 F" a Command5.Enabled = True2 j, u2 y R# V2 d/ u7 s2 U Command4.Enabled = False B/ E1 y" ?* h2 U. h5 v% eIf PortNo < 0 Or PortNo > 32767 Then + x; S: h! o3 KMsgBox "您的输入错误,端口超过范围" 8 \3 ?. Q8 H$ [% T4 o. XCommand5_Click , p2 ~. U: U8 W! s YExit Sub/ U7 I, }2 s( u$ e; D Else2 N0 e4 x! c$ W( O Winsock1.Connect Text1.Text, PortNo ( l% a8 ^: O' [1 H0 Z2 \Text4.Text = "开始端口扫描......"4 }. G) M# V3 p _9 }* T# J End If0 _! z. z0 C! ] End Sub U0 a: _+ v! w4 _9 Y! {3 X6 rPrivate Sub Command5_Click()! Z- c7 v/ V" d/ J Command5.Enabled = False ' w- N j8 y j/ g" qCommand4.Enabled = True , G$ }& U4 r# T( {6 n7 N1 mWinsock1.Close 2 F) |2 Y; K3 M; |8 W2 r) @$ n2 i$ fText4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" , e8 L6 k! q6 W+ P- y( PEnd Sub" v* W4 x2 y0 S) R6 L Private Sub Command6_Click() & G# r4 Y. { lMe.Hide ( {$ s; z* J4 F- n- l( [5 nForm2.Show ) v0 I- u$ V4 R: M9 p; b* @End Sub) b* Q$ P, m K. ` Private Sub Command7_Click()6 k5 D3 W$ N+ x$ z% i, ]) i- e FileName = "d:\ipdetail.txt" ) n' |* G {* @; G6 LShell "command.com /c ipconfig.exe >" & FileName, vbHide ) W2 l2 p. }3 ~9 BDoEvents : ]- \* j$ O% X6 D n7 l+ cDo While Trim(Dir(FileName)) = "" 8 q6 q3 |% ?- ~) d3 P% h% CDoEvents/ h8 b5 z) L( ^/ ^. G Loop 4 ?8 x$ K* A3 b" L& P5 SDim strstring As String, FileNo 0 d9 E% J, q: e5 k7 g9 d vDim sVar! w) K B0 A9 D8 T If Winsock1.LocalPort = 0 Then3 g6 _# T, M$ [5 J7 Q1 o strstring = "端口编号未设置!" S8 D$ j% M7 O8 }9 f% `' Z Else 7 Q w8 Y( @( x4 c" J, Z% [strstring = Winsock1.LocalPort # T9 q% }. ?; X9 q9 d) M5 LEnd If , n4 N2 n; p7 MText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf 3 `8 V5 R& O8 I% OText5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf% F3 F" n( W7 @ P$ Q( L Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")+ o8 q" d$ I, a FileNo = FreeFile()- ^; v! g" P$ L Open FileName For Input As #FileNo4 ^# l9 P/ l+ P( U, @# M While Not EOF(FileNo)0 U; Y( a" _; o- E. _/ W4 S Line Input #FileNo, sVar 1 o( g& \0 @8 C9 x+ z4 Z: YText5.Text = Text5.Text & sVar & vbCrLf: z: Z* ^ B' k2 M$ [ Wend & r" b3 G2 m. F: f( v5 UClose #FileNo5 u5 P% G2 ]3 e$ r7 x MsgBox Text5.Text : H* e3 f+ }5 a( wEnd Sub1 E) m9 }' E# i& o Private Sub Command8_Click()0 b4 ^' F3 L* I% X% r. T MsgBox "考拉制作!" 5 h2 q( R, ~) O6 T2 c7 v3 xEnd Sub- X! n/ q# v. J# ~' s* w% c7 w- ~" \ Private Sub Winsock1_Connect() * |/ Z* ~0 Z# h# t6 \8 J5 e8 b" A% eText4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf ' [* ~; K) V. I7 U/ PWinsock1.Close : O2 N5 O) P: [3 B8 PPortNo = PortNo + 10 l2 V1 {' \, h# C+ o" h! L) d If PortNo <= CLng(Text3.Text) Then9 k4 J5 s+ _1 x. y# ^# _ Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo 6 Y+ e6 h, z; w z2 Q# nElse* @4 ]# N" R3 y7 Z! u; K Command5_Click ! m7 Q: m& b5 S3 y3 tEnd If; \. n$ \8 j, F End Sub . v& F" I( f+ A. n% j$ ePrivate 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)( @6 e$ @- |4 d: z; e9 K, f X Winsock1.Close2 Q' y$ x- p6 }: N6 i PortNo = PortNo + 1 * Z& [$ q8 Z; v& O5 Y" r: e6 j" _If PortNo <= CLng(Text3.Text) Then) {+ O4 p: E4 k9 C( {% n' y! N Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo + j9 m* C; {6 a, x! PWinsock1.Connect Text1.Text, PortNo : l W' w9 p; {% z" _Else 4 ?, b5 x1 S- a- q2 X' F2 ECommand5_Click$ p& Z9 |0 H' e' F End If ( R* k6 x0 h, tEnd Sub 3 b/ p' j9 ?# x* I3 _- H* C* M $ W! n A: L9 T5 [1 ` lPrivate Sub Command1_Click() . {% b- P3 C% m# ^# G' F0 ^Winsock1.Protocol = sckUDPProtocol % o- S2 m: K4 n$ u+ K9 |+ eWinsock1.RemoteHost = Text1.Text9 U1 G2 o1 {0 i; H' s) ^ Winsock1.LocalPort = CLng(Text2.Text)+ G6 D0 |/ f7 Q: E& {% |5 E Winsock1.RemotePort = CLng(Text3.Text)- w: P7 \' \ T( {7 F Winsock1.Bind 5 C1 `$ q2 a. RCommand1.Enabled = False+ O) Y! L7 N5 \/ S5 s1 e$ x+ g Command2.Enabled = True* b) E6 Y ?& k' [( { End Sub# L6 Y2 H* r: G( ^ Private Sub Command2_Click(); m+ n7 ^# ^+ l% O On Error GoTo ConnectError# c" m( |8 d6 @+ K( Z Winsock1.SendData "Koala:" & Text5.Text& L* s& Q% o# F8 Z7 s3 e Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text 7 {. R6 x! Y# ^- r! H9 pText5.Text = "" ! t2 d9 }8 C& wExit Sub " H1 {4 g- u! O2 b+ BConnectError:7 _- a8 q, z+ y2 J0 f9 L6 d MsgBox Error_message; n$ E, h" S5 W7 G End Sub 8 M4 g v* v% F; I& xPrivate Sub Command3_Click()1 m/ ^1 L: u; B- Y2 E Me.Hide + _- _) {6 ^3 i# V' LForm1.Show 0 a4 Z! o# m+ W$ l. ]6 ~7 FEnd Sub9 O0 l/ h. d, f/ E$ ~! @ Private Sub Command4_Click() . z5 Q$ M2 m2 C* B, SEnd ' [" e% s. g" a) _9 q9 o8 |" CEnd Sub8 e. \7 Q9 V) R0 z, y c Private Sub Text5_KeyPress(KeyAscii As Integer) / O5 [+ r- U- K6 {) }$ QIf KeyAscii = 13 Then/ b7 k) J9 _* T7 c Command2_Click ( F1 `2 t" s& {9 AEnd If ' o- ^8 N8 c; a" |8 a i5 [5 IEnd Sub7 G* K+ n X0 n6 \! |. _6 V$ ^ Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)' P' I7 Z0 m. Y5 w9 |0 V3 @# x Dim sVar As String ! n9 _ Q6 i# ~) I/ iWinsock1.GetData sVar, vbString3 k5 `- f6 E" j$ A$ n; d Text4.Text = sVar & vbCrLf & Text4.Text7 n, Q9 ]2 }. k% b. g0 n End Sub 6 @3 j/ \$ ^, A7 t. C, \ ! v6 S0 v& w0 a6 H. h8 i1 i$ m8 O" L" Z6 |+ C* }$ @( G 2 @1 ]$ g+ Z; G# i6 V+ a) H/ G 8 o8 c# G$ N9 }1 a ( F. R' a6 H) n) E
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
* ^1 o# W+ ?$ P3 }

本版积分规则

关闭

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

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