下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……
4 |# [: s5 N. n" i请点这里下载+ w$ ?0 N! U1 h$ {: T
恩啊……先打开后保存……5 {4 g  ~. U/ v' o$ r0 k' y
+ |  w- _6 _& e
; O3 m* t2 G0 n9 O+ x8 y2 s9 ], J
3 [. b7 `/ Q! x

# Z$ Y1 y* J9 `; U! C+ A! z& w& \* v
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
+ M- y4 ^1 D  \1 b1 v/ N
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long + z: W( H6 c; v5 mPrivate Sub Command1_Click()- m) X) Z) e A: v. ]: F. c MsgBox "您的IP地址是:" & Winsock1.LocalIP 5 n# H6 O; T$ V' ~: XEnd Sub$ {7 W8 j; B5 t6 M Private Sub Command2_Click() 6 {0 [! _. C) M9 ]1 R4 yMsgBox "您的计算机名称是:" & Winsock1.LocalHostName5 o! R) W9 u3 D9 I End Sub' M. [) s, w8 h3 A0 @ I& }7 Q Private Sub Command3_Click()$ v3 Y# ^9 q& H3 Q8 g End ! D4 ~6 W; c3 P- n9 E1 R' YEnd Sub J+ |1 o7 b/ b4 ^, } Private Sub Command4_Click() \. ]" n' m* ?. K3 k PortNo = CLng(Text2.Text) - 17 R& N7 L: u) i: p Text4.Text = ""! b- e$ ]4 {. `; S9 c7 o5 d Command5.Enabled = True % l2 _* ]& {( _5 F8 y3 Z& nCommand4.Enabled = False . K, J$ z, [ S! ~7 A' kIf PortNo < 0 Or PortNo > 32767 Then% A9 o9 j! t$ G' c2 u7 a3 \ MsgBox "您的输入错误,端口超过范围" 9 g* D6 r9 {' m5 V2 I1 vCommand5_Click 8 V9 b( V, @. @) A7 uExit Sub 3 X1 v: w# u( F1 aElse , {1 T$ }# Y7 fWinsock1.Connect Text1.Text, PortNo ) P# x0 U: c! `) C+ ^3 P: ]Text4.Text = "开始端口扫描......"1 c2 ~- O% S6 a6 l: a, e! j0 ~ End If5 f4 e; a: O4 q End Sub 0 p: [1 V" C; r7 xPrivate Sub Command5_Click() . E: l7 L3 ~8 OCommand5.Enabled = False % T! u8 ?6 y/ E: M5 HCommand4.Enabled = True+ M4 O1 a- l+ o3 k% N% P2 R" e Winsock1.Close+ q3 @2 }. S0 m% W7 H Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" 4 J2 E% Q. X' u- P' d4 ^End Sub3 M2 q7 v, O2 w1 X3 m6 s Private Sub Command6_Click()' {/ L; W2 S" j I Me.Hide 9 W4 o$ a/ b( B6 D4 vForm2.Show / Y% g. ]; N, p$ P, [) ~# iEnd Sub 3 V+ u! g" l: i6 [- t( J; H8 f& |Private Sub Command7_Click() . y0 b& H8 X7 g2 Q3 Y9 YFileName = "d:\ipdetail.txt"/ X9 x ]1 j* S6 K8 s6 h6 ? Shell "command.com /c ipconfig.exe >" & FileName, vbHide! w( t# U! ?& Q0 r; q+ _ DoEvents3 N ~- c, @5 f* Y, S* X8 | Do While Trim(Dir(FileName)) = "" 5 f+ X* _% a7 F2 y2 U4 `) h/ YDoEvents 2 I; r8 G& \! L0 v; O/ a4 j# GLoop 5 r$ {- n8 ^. j; [# f- ^5 e( n) NDim strstring As String, FileNo' V1 q% G; o6 j0 t3 M5 [ Dim sVar 4 Y! k- m5 Q# \& {6 x4 jIf Winsock1.LocalPort = 0 Then * ?+ d% d, ?; l0 p% [strstring = "端口编号未设置!" u) U! r# I- K. I' L6 _; KElse , c7 I' m; H* v1 U3 @" ~strstring = Winsock1.LocalPort & o2 x1 K, N: g# z; L. w! lEnd If3 k; I& U! M* x9 H Text5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf 7 f. |/ S& a9 o% b0 ~1 SText5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf : J. b2 R8 w" d: A! E& i% gText5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议") . }" \% O4 h; ^. L; fFileNo = FreeFile() 6 {; n) h% r. k5 [Open FileName For Input As #FileNo ( i; y2 C+ i3 wWhile Not EOF(FileNo)! u: v0 z0 }9 U3 | Line Input #FileNo, sVar* a7 k5 u; K0 ^- d# f Text5.Text = Text5.Text & sVar & vbCrLf; P, U: P- \5 @: B& O Wend: G" {8 g, u2 p# H" m4 h0 K Close #FileNo ' k7 s2 n3 \$ Q, H, m5 w- g9 eMsgBox Text5.Text 2 s4 O+ b( I J- ?. J. J* `End Sub3 L; U6 [' g, U Private Sub Command8_Click()/ t/ B, c/ R$ f1 D* }4 p6 m1 T MsgBox "考拉制作!" & |! w! |6 Y3 n& _6 D" `# d8 _End Sub- R0 K) |0 ] _( t9 p Private Sub Winsock1_Connect() : {3 {* X% {, O/ @Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf 8 `- l# x, g; s+ SWinsock1.Close9 D6 `9 i' V) P) v7 ]' N PortNo = PortNo + 1 ( c& m) b6 n6 ~8 d0 r( {If PortNo <= CLng(Text3.Text) Then) C9 c- Q6 r( O, ` Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo 2 b# ~6 d' C3 m% I1 m/ c' ~* QElse ) \. Z6 u% ~, I: s/ P& qCommand5_Click 2 F6 t& V$ q9 p+ t- vEnd If ' v, u) ~! g- qEnd Sub 5 r" @/ f1 v2 C: n; lPrivate 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 @$ }* X# n8 |& ^9 R Winsock1.Close & g$ s/ N' [2 [8 h4 |* m% S& LPortNo = PortNo + 1 ' ?: n8 K0 L! c/ f5 y6 cIf PortNo <= CLng(Text3.Text) Then 5 A3 f1 u6 J& UText4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo . a0 G: V! F, ^( ^' OWinsock1.Connect Text1.Text, PortNo% ^8 n0 e) @8 S$ w% O. A& [! x Else : R! x/ `& @* HCommand5_Click * S1 \/ a" s- O2 P3 PEnd If O! Y) Z7 n) s* r9 b End Sub! _# G) T3 f" j) o' E ' c' D/ t3 l. {1 C$ QPrivate Sub Command1_Click()* J2 u" u! c4 V! [ Winsock1.Protocol = sckUDPProtocol ; M& ?8 C" J, w s( e3 K% d" gWinsock1.RemoteHost = Text1.Text& B2 {+ C% n6 q2 v1 s( W3 b' ~ Winsock1.LocalPort = CLng(Text2.Text)6 u' x4 z( |" J. G7 g Winsock1.RemotePort = CLng(Text3.Text)9 N' R( K( K1 C) r Winsock1.Bind * ?1 H9 M/ ~/ xCommand1.Enabled = False1 `2 q! ~) C2 e/ t/ ]1 W+ U" E, w7 \ Command2.Enabled = True ! r3 a4 o$ E# G6 C I' b( nEnd Sub 8 z- `, M3 O% g0 o% _Private Sub Command2_Click()$ ~2 Q9 \) F$ c& U+ [+ Q+ G* r On Error GoTo ConnectError5 G- J4 O# {8 ] Winsock1.SendData "Koala:" & Text5.Text ( U+ Z4 y- z: P( K3 CText4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text 2 K$ @" T7 w. Z- u0 V& JText5.Text = "", J. ~2 ?9 b& J5 R+ u1 L J Exit Sub 2 u! j* Y; `8 P5 {- i3 t1 b' W8 gConnectError: . J# t: E/ f9 ~MsgBox Error_message 6 l7 C, s. F1 _4 t% ~End Sub " G- t. J+ E% G$ e4 HPrivate Sub Command3_Click(). d7 L3 E3 |" E* Z6 ? Me.Hide ( M& u% s6 I) M7 j XForm1.Show 6 G; b% ]4 A1 q) sEnd Sub ' e, `% N7 C* i0 U2 E6 P$ r$ X; ~Private Sub Command4_Click() 2 D3 I1 d+ ^- W G+ r; ^End) |8 j- I2 g O End Sub, j T' P# |9 J Private Sub Text5_KeyPress(KeyAscii As Integer) |) r$ b2 }8 h8 T2 | a8 vIf KeyAscii = 13 Then8 J" C( L' o4 b, V0 t" W. I# L Command2_Click, n k$ T1 e/ B8 W' P( C' S End If . F: W) `# ]- v& s4 E1 l0 G: ~ xEnd Sub# f0 q: b7 J& U4 f% G" I Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)8 [* k1 D, r- H' t& J Dim sVar As String ! ^" n1 Q4 L* p O$ x9 M0 k' ]1 w$ wWinsock1.GetData sVar, vbString / E; `0 i( o0 W& q7 c; HText4.Text = sVar & vbCrLf & Text4.Text + P* ]+ ]; N1 e2 V8 W8 ZEnd Sub 1 R# l& {( E- o5 |5 q* N' U [$ ~" r; e# v* ~" R' Y) h0 d: _# c/ ^ 0 `- P( K l: C. S& h3 l 0 }2 U- o# E9 s& L! Y- p " M y: {3 y" Q) c( A2 \
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
% f( e' M7 s/ Z( X9 s

本版积分规则

关闭

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

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