下沙论坛

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

用新浪微博连接

一步搞定

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……
3 T; s0 s, d( l) y% ?4 q0 [5 a  o请点这里下载  K/ Y, P/ N& a, j' x- S
恩啊……先打开后保存……
7 G- I1 X# U- ]3 @  b  ]/ ~3 t8 I. _: L$ T& t7 s

9 W/ E6 {+ A* M1 N( Y2 U6 |: Q0 Y& o/ ?1 l7 n$ Z

2 O: D3 _, f6 x$ I% M4 F( ?5 I7 P! D2 h. R
[此贴子已经被作者于2004-5-12 20:15:18编辑过]

4 [, [: [% H) ^+ u' A) H
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩 转发到微博

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long 0 }" u% f, \( \8 Q7 ~% d+ }Private Sub Command1_Click()2 M$ J O& a9 y4 K+ S8 ? m, b MsgBox "您的IP地址是:" & Winsock1.LocalIP 9 _) U2 k( m6 M& U7 y- E, u& f) p9 Q; |End Sub7 r. y" z" x* {, ~- Q3 A) Y( | Private Sub Command2_Click() . w _9 W6 y: p( J2 oMsgBox "您的计算机名称是:" & Winsock1.LocalHostName6 `4 A" B1 j3 c" K$ x5 G# R( p End Sub ; G/ B" a C- T& i6 }0 D# u1 ]Private Sub Command3_Click() 8 e9 H5 S$ F& m+ \3 e) `8 [End6 `5 h4 U- @1 e: h. ^! t( \: M End Sub ) [8 O7 k3 q/ g$ G- d5 KPrivate Sub Command4_Click()6 p# y0 h2 L% q/ \- v PortNo = CLng(Text2.Text) - 1 0 |0 m4 S* k9 a& I P1 HText4.Text = "" m# s4 g0 H9 s+ L( ?" g Command5.Enabled = True: G2 C' X2 w$ R* G n3 N% ? Command4.Enabled = False) x, B5 B: Q$ X& p4 N2 O7 c- } If PortNo < 0 Or PortNo > 32767 Then 4 n$ ~* j. E1 P9 H- u1 eMsgBox "您的输入错误,端口超过范围" ( u( | v2 O( G; u8 qCommand5_Click( ^3 b; Y5 K3 L& F' T7 w Exit Sub 2 q+ J# A/ L$ ~ Z& TElse : b5 @% b" ~# h7 m6 o0 o0 X2 QWinsock1.Connect Text1.Text, PortNo* G* w3 U2 x J6 Y6 P4 }' @ Text4.Text = "开始端口扫描......"# D! y1 e) m1 W/ P End If, `0 S4 M7 G& F" H End Sub * B$ p+ C* B8 l* l" D; e: K* ^Private Sub Command5_Click() 6 t) v/ q) R4 F5 g( G" ECommand5.Enabled = False / `2 P: c( G0 E hCommand4.Enabled = True + z0 ^. h- n' ^ p. `8 p; {& QWinsock1.Close ! r, G E: D, r3 }1 r L6 Y! p7 J1 pText4.Text = Text4.Text & vbCrLf & "端口扫描已停止。"% r4 a/ x% L$ v, q, s& c8 V' m, j End Sub 3 O2 x" M1 `9 l4 H u FPrivate Sub Command6_Click() , o- U7 a% o: P9 F) D, r8 _Me.Hide% U/ h& m; N. K1 [. c& L Form2.Show) v! ~8 |4 _; M: O4 h End Sub" k* I* b! e3 I4 ?, \8 K! t! W B Private Sub Command7_Click()* m8 W0 K+ d9 ~ | FileName = "d:\ipdetail.txt"& V2 l& `. C. v2 Q Shell "command.com /c ipconfig.exe >" & FileName, vbHide 0 L( F% y- V! E7 vDoEvents6 f) y( ^0 i% s! z8 Q8 ]/ R$ | Do While Trim(Dir(FileName)) = "" / r. L. v E+ K x: e6 uDoEvents ( Q, c! j# D% Q+ yLoop 8 N! u x* Q& u% MDim strstring As String, FileNo8 N( H6 Z7 _1 v, o* h8 ] Dim sVar 4 ]3 c9 p; U( g3 g8 @5 x2 c, rIf Winsock1.LocalPort = 0 Then ; c' t b$ P7 u1 y d* B# Wstrstring = "端口编号未设置!"0 q! p. y" t9 r' T& h2 @( l Else( |5 ?$ \* ^" ]) m' |" [! @. y strstring = Winsock1.LocalPort ( w: U3 J& W7 m6 L6 {. R: }End If 8 [5 \$ o* ` r5 OText5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf; [- Z7 _' A! O Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf ; \% L. B/ w8 f: |4 J4 X* ?Text5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")# n) c4 f) }" n7 Z, {, ? FileNo = FreeFile() + a' y0 b5 V) J8 {, V" G7 n) gOpen FileName For Input As #FileNo 1 Z+ g) j+ t% N" U' uWhile Not EOF(FileNo) 2 V0 [' f) p$ W* }2 g+ P! |Line Input #FileNo, sVar % M/ d$ R" d) \6 a* O/ C; _Text5.Text = Text5.Text & sVar & vbCrLf / V1 s- c# S! Q: C" g7 X3 N( ~Wend 8 o* }% C/ X$ }( H( A6 K# vClose #FileNo1 v1 g0 {7 F$ Q MsgBox Text5.Text 7 S- V) G2 z- vEnd Sub $ t' B- u4 \$ J$ ]5 S' C4 dPrivate Sub Command8_Click() ! g% q9 \* [* `5 u! [1 u9 R, tMsgBox "考拉制作!". w. B5 g2 c7 X' Q( O End Sub4 Y0 E5 T7 t6 X1 }8 D$ F Private Sub Winsock1_Connect() % z' z3 l9 L3 EText4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf$ D/ @* Z- n5 N. o; C8 i+ n Winsock1.Close & d$ w$ o) R" V i8 n2 G) N. N- W# n3 FPortNo = PortNo + 14 _8 P2 w9 k6 @5 l/ Z If PortNo <= CLng(Text3.Text) Then! [; J2 n+ _% d Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo 6 }7 m/ L# J! T4 D0 H e1 @Else / E1 `9 F: ?, x- K9 ?: I4 Q; kCommand5_Click. s$ }$ L5 v2 Z* @( w# W End If+ A& \2 W" @9 \* J- D" _ End Sub 1 P: Y" Y k+ m3 d: U7 i- 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) y6 d- h1 `/ o" Q+ `% OWinsock1.Close) [! f# Y, Y7 Q8 V" m PortNo = PortNo + 1 ! d4 I. z, r; q* Z9 vIf PortNo <= CLng(Text3.Text) Then' N! p+ z. g p( I, q Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo4 J! [1 s9 N0 m Winsock1.Connect Text1.Text, PortNo 4 R! q6 H% G4 w8 x+ mElse: {$ z4 h6 _& Q/ x! K/ Q Command5_Click3 U. w! [# n3 e/ O% b/ { N End If* A- [2 E- Y; R: C7 M7 i End Sub4 Y5 b- E/ m. v/ B # |4 q) I) y( R+ u* s1 Y Private Sub Command1_Click(). x- z, b: `8 m9 k+ K' F& ~ w) j Winsock1.Protocol = sckUDPProtocol % @ _- \* j; c" P! E' mWinsock1.RemoteHost = Text1.Text # {/ b3 Y1 @, s. h0 J+ f) |, lWinsock1.LocalPort = CLng(Text2.Text) : M1 \6 w( s$ z. \" M+ Q& ~8 F( pWinsock1.RemotePort = CLng(Text3.Text)2 j' R6 V, b! U5 z: Z2 p Winsock1.Bind* X. N% v! \. S" Q: o; Y4 o Command1.Enabled = False+ n7 C* E- L( V' S Command2.Enabled = True- E8 Z5 _, ]: E( L, H: ^ End Sub- m; g$ A" ]& F# N& D1 w5 n" ~ Private Sub Command2_Click() ; N# H' o+ I) O; S' X8 ^On Error GoTo ConnectError ! S0 d, C% A, Q- N4 d% h1 tWinsock1.SendData "Koala:" & Text5.Text1 h% k. o y+ J7 j! G" X3 [ Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text: M& _/ ]2 T" Z Text5.Text = "". u5 ?& I6 V- h8 Z Exit Sub ! M3 p! G4 s0 P5 @3 z6 i2 fConnectError:/ ~: X+ @8 W" n8 E/ o MsgBox Error_message 0 B* D& B" x1 S7 O2 g" xEnd Sub% d$ O- _5 T/ @2 D3 j Private Sub Command3_Click()! m& T) | V. B$ g: C$ } Me.Hide 7 F$ N2 R# T [" gForm1.Show 6 x( K9 v' @( M OEnd Sub ; Q2 s: y# G: b6 J3 J/ k! YPrivate Sub Command4_Click()+ ?) A% D; T- X; k3 S End 2 J" W. f) g9 AEnd Sub( @$ k% }# a- x$ k4 S2 y: Z' p Private Sub Text5_KeyPress(KeyAscii As Integer) % U: @& y9 ~' y8 b# _* ^! k c. NIf KeyAscii = 13 Then 1 }2 a; D8 b' ^4 v) S6 JCommand2_Click ' d* Z- E& r2 M; DEnd If . A' T! | O8 i0 h) m% rEnd Sub 1 |8 I! M4 e: W* [- t9 }, _$ I; kPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long) # W$ o* o2 x. y7 N3 eDim sVar As String " H( K) ]! R6 A v; a8 _* fWinsock1.GetData sVar, vbString 9 z2 B( w/ _6 |, uText4.Text = sVar & vbCrLf & Text4.Text 0 |4 S6 p- y3 w8 p6 f- s" ?, U0 I: j" vEnd Sub! b2 }, S Z6 m3 y4 `, K * K D+ f) V& \ F7 E: { 8 G; ]( x, `0 V; C$ T" C 0 k4 V0 J6 I4 v3 z ) h3 e5 o, a1 I8 I" X 6 o) ^/ y# w3 k: `, d
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
5 y8 r) p6 J. y* I i+ l

本版积分规则

关闭

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

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