下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……
9 l# ^5 e  T0 ]& Z) R4 Y  i* t请点这里下载
( _0 n8 b  {6 C恩啊……先打开后保存……- A! F; }  ?3 }) |" B
0 j. D% r9 j: _5 U+ X

( ~, [9 f) Z, w; m
1 _- C7 M# z2 o. ?% m
# T& O$ g+ }: x' ]# N- u
9 `- ]+ m5 E, U8 ]
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
5 U3 Y7 v, ~' B7 T
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long' b, h5 a9 V" U0 ^, m) p9 E Private Sub Command1_Click() ' j( }( C; `' v: S- [/ LMsgBox "您的IP地址是:" & Winsock1.LocalIP : r! @1 C( }. x2 {/ e1 nEnd Sub " p4 W( Y5 N3 U" YPrivate Sub Command2_Click()& A% e2 R: u( f3 o. q MsgBox "您的计算机名称是:" & Winsock1.LocalHostName; G' a2 S$ O- u3 \$ O3 L# ` End Sub 6 I! Q- }, X2 }5 g) h2 IPrivate Sub Command3_Click()0 R. }7 p, u, ?! V End 6 V M5 L: ?; h; WEnd Sub / m; F! n( K/ B6 B/ @6 `; rPrivate Sub Command4_Click() % |7 w! q2 _" MPortNo = CLng(Text2.Text) - 1 1 j5 u' I2 }3 \: e3 B# ^; [Text4.Text = "" ) R1 G' @# Z8 Y4 q9 w, qCommand5.Enabled = True* Q( K( J( ]1 S0 Q Command4.Enabled = False " a; f; z% l9 K' o8 ]- L" N. K% rIf PortNo < 0 Or PortNo > 32767 Then( e3 ^8 g5 H. y' ?. O$ E MsgBox "您的输入错误,端口超过范围" 3 W4 B# D) Z2 U* C6 aCommand5_Click) A9 Z8 I6 _3 s. T Exit Sub ( h' f6 ]4 x! D/ F# C" n, s6 z5 yElse9 I7 ]. @, d( J' c1 @7 i$ \ Winsock1.Connect Text1.Text, PortNo ) z4 h& C6 G' I% @8 X' jText4.Text = "开始端口扫描......". ?& Y2 \* W( S" {5 @1 N End If! l0 Y' j% @* \* }- ?' t End Sub ; h$ j. B' j' z/ m) O! W. DPrivate Sub Command5_Click()8 r& [# y6 y4 v1 E9 H Command5.Enabled = False + X% ]3 f0 _4 x* R7 q; zCommand4.Enabled = True 6 u, ]/ X3 B4 y1 _: u. O5 EWinsock1.Close$ a; M$ w" V$ a P0 \4 \/ J Text4.Text = Text4.Text & vbCrLf & "端口扫描已停止。" ( u, `8 d/ I8 U& R4 m7 HEnd Sub8 P! Z/ T9 ?+ r$ T Private Sub Command6_Click()0 i3 K' o* m5 o Me.Hide 7 y7 h: g/ i6 L/ A& g; _Form2.Show & G1 i. J: t' d4 ?( T4 jEnd Sub( J5 G6 d) N5 ^, r Private Sub Command7_Click() 4 h( u2 l8 R# V' d0 }/ r& xFileName = "d:\ipdetail.txt") f* Q, _, x Q" n+ D7 i1 Y5 ?2 ~ Shell "command.com /c ipconfig.exe >" & FileName, vbHide; K: [; `& Q0 t- l0 q DoEvents 3 b* F) F4 B) p2 W$ P. r, lDo While Trim(Dir(FileName)) = ""0 G9 j+ B% w# a$ o DoEvents 6 j/ b9 O$ R7 k/ x, wLoop; `$ l, x% F' i% k( u! p; e0 ` Dim strstring As String, FileNo: Q- V) G- V/ A: U9 Q Dim sVar * J6 x* ?/ U# oIf Winsock1.LocalPort = 0 Then 4 E {4 O$ Y, p$ p6 ]6 {9 istrstring = "端口编号未设置!" 0 f7 Z3 G; N* y* rElse 5 G7 z2 l. c* Astrstring = Winsock1.LocalPort& P( B$ [, k+ F& J5 i5 @ End If- @8 Z2 r9 f w6 n; b% R7 I+ q) u Text5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf2 ]. ^/ s5 Y8 K6 E9 m0 k Text5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf % J6 E( G3 ^0 v W" ?! JText5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议")% f7 v4 j1 p7 B3 |! p3 S8 P FileNo = FreeFile() ( |4 P; L8 u/ H* ~) J' M& R6 uOpen FileName For Input As #FileNo r" X9 V. _9 i) `) v1 \; XWhile Not EOF(FileNo) # N' W8 A) j H6 j* R! c& g3 `Line Input #FileNo, sVar 0 o. V B& ]! DText5.Text = Text5.Text & sVar & vbCrLf: m9 ? k, t5 ~6 E/ {( ]9 T! [3 z/ ~4 J Wend5 ?( C5 E! q2 e7 {+ G Close #FileNo 8 o/ Z! I; @3 ^9 `/ CMsgBox Text5.Text / n2 F( w$ o' A6 ]. l+ PEnd Sub# Y# [2 W' ~) h3 W4 M# O8 Z Private Sub Command8_Click()1 A1 _# u' I7 Y, w MsgBox "考拉制作!"; `" ?; b0 i* D! M" S% f4 i6 L End Sub 9 |% |! R$ R4 V' B1 O3 x5 ?Private Sub Winsock1_Connect() ) n3 m( o( n* j: X5 U [Text4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf5 g x. ?) }9 w4 u9 B3 U Winsock1.Close. Q! ~4 K8 L. a4 u, r" \ PortNo = PortNo + 1% ^6 C4 N0 \( ] If PortNo <= CLng(Text3.Text) Then5 E6 j! u* b; ` Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo" q" h+ ~+ J, \' K- X% ~ Else ' N* @2 k _8 P0 d6 W4 ~" M" ?8 WCommand5_Click/ m) `: p, f1 l) a End If ( d: j8 A+ t4 Y6 h1 tEnd Sub% @! f h- ~+ h$ {8 K 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)" `+ D g6 G' Z Winsock1.Close - p, Y$ P) F3 @0 T+ ePortNo = PortNo + 1$ B8 s# Q+ Y$ J If PortNo <= CLng(Text3.Text) Then8 i; Z4 y' Z6 E# T$ `3 D2 }' y6 F Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo 2 \( v, X0 I0 o$ L7 IWinsock1.Connect Text1.Text, PortNo! {& g' p( ?! x Else - F5 G! p8 j- }) p3 C( XCommand5_Click ) K; z4 I5 d- a( _, F+ sEnd If1 i# w5 {7 {0 G; b( L End Sub! J) S' c+ z( b# ] " K. q# x4 u+ Z4 t- WPrivate Sub Command1_Click()& a# c6 F& q8 Q! W( c Winsock1.Protocol = sckUDPProtocol; O5 Q0 B% E4 W Winsock1.RemoteHost = Text1.Text 9 {- \6 X# A/ k/ yWinsock1.LocalPort = CLng(Text2.Text)& k$ Q8 B+ S% L2 C4 b6 ]* B Winsock1.RemotePort = CLng(Text3.Text) % V9 H" v8 ~1 {9 @Winsock1.Bind ) l' A e( M+ j" l. iCommand1.Enabled = False ' T+ q1 ]* n i; z& o! ~Command2.Enabled = True6 v+ u- J" R+ F+ H" p1 G; n8 o End Sub1 D8 `; U0 E# u! e Private Sub Command2_Click() / p: s1 R0 R4 H' KOn Error GoTo ConnectError& \" Q8 C" P3 d4 ?2 L% N Winsock1.SendData "Koala:" & Text5.Text' k" c* B3 q9 j8 _/ \1 d. \ Text4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text ! G! [. P" I2 a ^Text5.Text = "" / f' ]/ Z: G% F& v; [$ {Exit Sub % S/ \+ y9 s; ?, p& W9 QConnectError:6 {1 v/ ]' H' x; t, h MsgBox Error_message : J6 b+ o5 S5 \0 j5 eEnd Sub$ [+ q2 U/ e% x5 e. o' Q, f Private Sub Command3_Click() G9 G. e! o" X! HMe.Hide ' W; h5 ]5 p- S) n3 |Form1.Show. s4 j% ?& ]8 P End Sub% p; c$ i8 E4 t; { Private Sub Command4_Click()* @& ]3 s) i: G+ x4 F. v End , k: k" Z' T* h! p' i, }End Sub * j* l8 h& o% OPrivate Sub Text5_KeyPress(KeyAscii As Integer) ; i7 F4 ~$ A* ]/ `If KeyAscii = 13 Then4 o) N+ i0 G! F X) r1 v- v8 R6 u Command2_Click/ m- J' ]: \! [0 l( S* n' f End If C, G, a( J& J2 e0 HEnd Sub }* v% U2 e% F K, w0 B1 RPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long) 8 C! y! ^) X4 f% V5 e8 ODim sVar As String + B l: o4 q/ ^# W% r/ F8 dWinsock1.GetData sVar, vbString : ] k8 c3 [1 D( _& T) ]8 }Text4.Text = sVar & vbCrLf & Text4.Text, B# s" ?/ O; ^9 d End Sub ( T0 b1 o- v/ D9 U' H& ~ 2 s! x+ _ w* O2 c1 n% g G: g: a! h- h( k. ? 4 ~2 P3 r* f0 `7 w& Y & t6 E+ a _- d/ m4 M 9 `' h: H( v4 ^, B7 b$ s1 u( m
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
0 l6 D6 Y7 G! ~, h/ r1 F' o$ [1 v& z6 M

本版积分规则

关闭

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

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