下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……
' G0 {7 Z. K/ m. @0 ^' C$ \请点这里下载
0 d7 q* W. k% e. P7 S5 u3 o恩啊……先打开后保存……
& R. b( L" @$ \8 U/ h! L  V0 f0 e' T
3 L$ J4 m2 {) I5 F1 g  [6 Z5 ?
- s4 w  a+ n: H% F5 P2 Q2 U; r1 G  u! ~3 V4 m

! x( ^# G4 U- g) T& w9 H" o& y: N! ?3 Y7 t# {, G7 x9 b9 ~
[此贴子已经被作者于2004-5-12 20:15:18编辑过]

1 W" M) {& h8 D# S: e9 p
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long& L! [7 W2 X! i8 m Private Sub Command1_Click() ! j; ]8 g4 K+ @6 u0 ]( \5 x5 IMsgBox "您的IP地址是:" & Winsock1.LocalIP4 `* E. w- [9 E, w9 z/ v End Sub0 K3 T8 [+ T1 z7 m Private Sub Command2_Click() * p }" h0 |! m8 GMsgBox "您的计算机名称是:" & Winsock1.LocalHostName9 [; |/ `2 s4 d, `; k, Q+ \ End Sub% D0 Q' A# }+ e- f Private Sub Command3_Click()! O- P# w& i. n2 s# z7 u; B End- }/ n; `" O7 d$ f End Sub( b5 v% a, q+ z4 N3 X2 s Private Sub Command4_Click()4 A: P( s/ q& o% ?0 Y6 V PortNo = CLng(Text2.Text) - 1 3 J3 B6 L; |, k r( d- y H \3 OText4.Text = "" s. s: C0 Z4 s+ M& K X/ _ Command5.Enabled = True i! e* S$ v' W( k( ACommand4.Enabled = False / k6 z4 G: d: G9 Z* b3 yIf PortNo < 0 Or PortNo > 32767 Then & r8 ]( V; b1 L" l( gMsgBox "您的输入错误,端口超过范围" + \! F" W- N- o3 GCommand5_Click 9 E. N* P# r P9 A& C6 hExit Sub # }% k3 I2 ~) G: bElse , z; D, T; k) JWinsock1.Connect Text1.Text, PortNo/ j8 c @6 {+ y4 e Q Text4.Text = "开始端口扫描......" / ?1 W2 I) b4 b) ~End If0 `3 W: [. q. m End Sub / k- Y9 Q; B( UPrivate Sub Command5_Click()( m9 c& A3 b, j, x Command5.Enabled = False0 D/ O& X4 L V6 g8 O Command4.Enabled = True $ L, n1 \) Z. c" OWinsock1.Close * i/ r/ p/ F; J4 S2 \: T! wText4.Text = Text4.Text & vbCrLf & "端口扫描已停止。"9 Z t0 u& J/ \* Q9 I End Sub h! K/ A: J0 I |7 zPrivate Sub Command6_Click() 1 R3 s7 y+ { D$ mMe.Hide 3 \2 B' A3 V I: [# TForm2.Show ) n/ z4 o3 l) I- E0 x( p( TEnd Sub, F) z0 C' J: a& O' y; R3 M' ]" W- a Private Sub Command7_Click() + h7 T- k9 c/ X0 N- A" L' U, i8 dFileName = "d:\ipdetail.txt" 2 u8 R/ j; u% @0 R# O; j+ c' dShell "command.com /c ipconfig.exe >" & FileName, vbHide ! F, O, x) G2 y. M4 y# tDoEvents. m6 c! _/ a" F' i/ W! E0 l Do While Trim(Dir(FileName)) = "" ! l; U* V$ A: l T! j" PDoEvents s7 E% G7 m# c }4 n# WLoop1 }" C/ s4 k D1 r9 [, s Dim strstring As String, FileNo; Q' k0 G* U+ ] Dim sVar1 V6 A6 U8 l' P' S# c0 r If Winsock1.LocalPort = 0 Then " @. e- K: h+ e) m) i/ M% `5 q0 u; s5 Pstrstring = "端口编号未设置!" + ~' N9 q1 k; X0 [3 E3 TElse ! f4 ]5 j( j: L, `8 p# u4 ystrstring = Winsock1.LocalPort $ q3 r7 M& g) wEnd If 6 C7 X4 S$ ^6 ^7 A4 nText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf C W3 ?5 ], n+ Y+ u; L4 sText5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf3 g& U$ }, P" {4 y5 W) | Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议") G2 f& c( @ N1 `; J b' U FileNo = FreeFile()0 t" s2 W3 X% Q' ]- P' Q. |. Y Open FileName For Input As #FileNo : W8 [0 j( R- N2 J c {& m: XWhile Not EOF(FileNo) + r5 n7 K( q" m: y+ i4 p3 R+ P0 gLine Input #FileNo, sVar 1 ~- y) `% B' d3 F8 T/ Q1 ]Text5.Text = Text5.Text & sVar & vbCrLf , q, V4 l6 v5 K& U$ WWend ' z/ x! i A" d% k& I! }; ~# pClose #FileNo , c, e! F4 C0 O& w4 sMsgBox Text5.Text Z! ]+ t8 B# j7 {6 Y) a$ h End Sub a' P4 U% w, S1 [% c8 E Private Sub Command8_Click() # G$ ~* x% [- f# K+ sMsgBox "考拉制作!"8 T* s8 Q# D6 E0 T# P0 Y End Sub) d; F9 C6 e( b Private Sub Winsock1_Connect(), h6 [ ~' _( o# w% U( I9 [* e. x Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf: P/ G! L# j _" T3 y2 X' y Winsock1.Close$ ?" l* F) H. h% R8 H" f PortNo = PortNo + 1 3 \7 J$ W* b; R& l: R6 z2 fIf PortNo <= CLng(Text3.Text) Then# @& n9 X$ Y& {4 U& ^) {/ }1 g7 d& l Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo. C- p: {9 p" _# W- O; k+ d+ J8 A Else3 A9 e: c1 ^5 s! M Command5_Click8 z6 b7 W% W, z# g End If4 E2 T0 U2 A4 t; ]0 S End Sub, r3 d8 n: D5 V7 ^) t Private 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) 0 s4 {8 a" \( h# T! HWinsock1.Close 4 g/ s ^/ c, A) L! q% a$ hPortNo = PortNo + 1 . n9 n: T0 ^ l2 |1 f* i5 KIf PortNo <= CLng(Text3.Text) Then' Z7 S+ S& E/ l3 d1 O2 d Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo- c$ S ?6 A; s; ]' B Winsock1.Connect Text1.Text, PortNo / Y4 w+ g) k! I2 E/ G) y" IElse) e! s/ |! ?9 u( N# J Command5_Click 8 q' B" m3 ~+ NEnd If* i* N* l" V6 G" k End Sub [/ i0 d1 H1 S7 b0 e* i- e; Y& Q1 [$ L! H1 z& r* l8 P; e Private Sub Command1_Click()9 L7 h4 J! X* T" z$ D: U! H- c8 B Winsock1.Protocol = sckUDPProtocol 9 K& H6 u7 m O+ G, r0 D6 pWinsock1.RemoteHost = Text1.Text ) L# E j. `/ D l2 x$ t. r( xWinsock1.LocalPort = CLng(Text2.Text) 2 E# c1 U/ l: |. f& K" l) Q1 m7 BWinsock1.RemotePort = CLng(Text3.Text) ( S$ i$ W1 i: D' p2 c+ H# w; nWinsock1.Bind 2 Q1 @% ~" M5 v1 c" NCommand1.Enabled = False, P) X- p: n( Z% j+ @7 ` Command2.Enabled = True 1 c$ ^" d0 w0 | DEnd Sub 9 V/ ~9 f+ A. E& R* Y) }, c5 b' ^* J dPrivate Sub Command2_Click() 9 E* e/ w( ~' s, COn Error GoTo ConnectError1 Q( G7 E+ D$ U Winsock1.SendData "Koala:" & Text5.Text; [: H6 F f6 Q1 D Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text 8 {- C* Q; J2 {; v- i" WText5.Text = "" " |: O5 a0 x5 j# l1 N! U, `Exit Sub8 v1 B* l2 E T0 ? ConnectError:" j3 P2 `7 u2 f: c9 a MsgBox Error_message $ d% P3 L- D' n/ YEnd Sub * W7 `- s2 c' W* q6 R8 @Private Sub Command3_Click()' k2 d3 r6 W. b3 X0 I Me.Hide , ^' W+ C9 X7 X. NForm1.Show / E! t) f% j" _* ]4 UEnd Sub( Y9 b+ F, g- {+ c) d# P Private Sub Command4_Click() / N* G2 V4 i6 I' |3 \# h1 E uEnd; D. ]2 |, V) j+ K% _; h4 h End Sub : B! ~; t' O3 K" \& f8 z. @Private Sub Text5_KeyPress(KeyAscii As Integer) ' w$ e7 F, ?& Q, g: X% hIf KeyAscii = 13 Then6 i. W3 `3 q* _' y' K6 _, X Command2_Click 6 i- B; a# Y/ n% r4 `- x- CEnd If 1 V9 S# W) B" j, l; NEnd Sub X3 z0 ]1 w! Q3 aPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long) C5 w, Q, U0 f& H7 t& [7 W Dim sVar As String/ a5 z) r @6 N+ q t# @& ^ Winsock1.GetData sVar, vbString - V( C( F$ P' J- GText4.Text = sVar & vbCrLf & Text4.Text, L2 r# w* {- S5 l o7 L End Sub$ R- E" b! v( } ! K# b2 B& L8 M4 K8 n$ `6 z * s. r W; \5 B1 e! G4 n6 E7 d7 f, p1 J% E ; e. m+ p4 b6 K! g% j# U/ f$ p+ b2 G' [" R+ A) M/ r- L$ V, K3 x/ b8 K
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
h0 S9 `, m5 W6 H S' g: U

本版积分规则

关闭

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

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