下沙论坛

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

QQ登录

QQ登录

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

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

[复制链接]

该用户从未签到

跳转到指定楼层
1
发表于 2004-5-12 12:43:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在XP下VB6.0运行通过,有兴趣的看看……' P6 P$ I8 J% x, r, i) ~/ f+ L, O) Y
请点这里下载
1 L( F* {2 z; T恩啊……先打开后保存……
7 P5 A( l6 Q3 P  @5 T& z& I9 f( J) W  q% |/ C( ]8 Q) r, `' j
: Z! k+ e3 M4 X# @; M& L0 v7 N  F

, Q5 ^( c+ l: @3 i6 k4 d
+ d4 x2 ^4 |& ]  o: L8 a" ~9 `' v$ C  e
4 _- O! w- O) y0 v
[此贴子已经被作者于2004-5-12 20:15:18编辑过]
1 Y2 S* H2 r, V( X- D% ?4 H# e4 R1 t
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩

该用户从未签到

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

该用户从未签到

3
 楼主| 发表于 2004-5-12 20:15:00 | 只看该作者
Dim PortNo As Long ; |& _& Z9 y" h0 c% J; F l& DPrivate Sub Command1_Click() : n' S r) B. O, ^8 N4 u% cMsgBox "您的IP地址是:" & Winsock1.LocalIP1 W1 L% M' | y2 s End Sub ! i0 [2 S4 T$ Z+ L! VPrivate Sub Command2_Click() 3 R$ v) E! o! gMsgBox "您的计算机名称是:" & Winsock1.LocalHostName7 W a$ r$ b4 h( M$ l End Sub! g5 `3 h: C/ d) p2 r6 Q% y Private Sub Command3_Click() 0 R# K2 c' C+ B7 ?3 ?& |( z7 s0 GEnd7 V1 ~& d1 M$ p. }& v# p5 u End Sub+ }' o( u* q0 |0 U% M9 U. f! ? Private Sub Command4_Click()" c/ B6 `. [- n2 F5 P* S PortNo = CLng(Text2.Text) - 1 , _( b0 v" }5 d- H8 S$ Y3 ^+ `- KText4.Text = "" - U, I" e1 T n* J: {# B0 q oCommand5.Enabled = True* R( |8 @# {, n' T- v' J, q Command4.Enabled = False9 `$ r5 b i5 B2 ^2 w) z) T If PortNo < 0 Or PortNo > 32767 Then$ {% d) j+ F& \ MsgBox "您的输入错误,端口超过范围"! P) `( M' S, \9 B ^7 \! t3 ?9 \. F Command5_Click . g8 q6 |4 J: \! lExit Sub& Y* ~. x- a+ L: U/ x: N Else" p- m* c2 @. j( S4 ~, h Winsock1.Connect Text1.Text, PortNo) r2 B( O7 @; E0 B7 V, o& J; \ Text4.Text = "开始端口扫描......" 6 `9 G$ c, I; R$ y6 O2 j7 zEnd If5 O! h# j5 b+ X" p8 d, q End Sub ! N5 e2 ?) r, ?+ dPrivate Sub Command5_Click()' a& X% p6 M5 g4 \& ? Command5.Enabled = False ( \$ c% C, X4 @+ U& v- BCommand4.Enabled = True q( |8 E! ^9 [ V. DWinsock1.Close # i7 ^3 z! H# t8 A$ |% h, eText4.Text = Text4.Text & vbCrLf & "端口扫描已停止。"9 [7 p- p3 j( q6 ?6 r+ Q; k+ P End Sub $ b0 c/ S, k, P+ P) r/ F9 d) F+ e/ CPrivate Sub Command6_Click()$ w0 A/ L. L @# B7 @- U Me.Hide 1 d5 ^2 v& x% V8 ]1 v, \Form2.Show % `' a" I% _) |End Sub 2 F! q% | N/ v) kPrivate Sub Command7_Click() 0 Q4 x0 ~" Q6 t# jFileName = "d:\ipdetail.txt"3 U$ q( P. G" P% @2 n2 |, a Shell "command.com /c ipconfig.exe >" & FileName, vbHide 1 d( H7 q/ p7 {" `% cDoEvents 1 v) b- g0 i$ d2 N! rDo While Trim(Dir(FileName)) = "" 2 j( f% P& o6 ~' aDoEvents ) ?! Y- e' j2 u! M# c! {7 Y4 ~6 yLoop& r# o) w" r, v0 | Dim strstring As String, FileNo/ s3 [; F' s! \) u: U Dim sVar & u+ e/ b9 P, F5 DIf Winsock1.LocalPort = 0 Then% i+ J; H5 v! K0 ]4 v0 F strstring = "端口编号未设置!" 8 \$ l! q/ i ^# ]Else + w5 D+ H9 d! U: w [3 Z( nstrstring = Winsock1.LocalPort 7 s$ G% k: r( CEnd If4 g/ a! c/ b x# n/ `# z" s0 ~ Text5.Text = "您的主机名称为:" & Winsock1.LocalHostName & vbCrLf * A( K4 p7 O0 }/ V4 oText5.Text = Text5.Text & "连接端口为:" & strstring & vbCrLf 1 V) S6 k+ D ?+ l& W1 WText5.Text = Text5.Text & "通信协议为:" & IIf(Winsock1.Protocol = 0, "TCP协议", "UDP协议") ! u5 C, R' o: `7 X6 KFileNo = FreeFile()! v: i( F6 [- ?$ R7 h {; _5 e Open FileName For Input As #FileNo# R7 J8 P6 N; w% o# z While Not EOF(FileNo) ! I8 k, w$ B+ d6 w0 J+ ]2 X: s dLine Input #FileNo, sVar' m+ z* k0 ~1 a( ^1 B# M Text5.Text = Text5.Text & sVar & vbCrLf ; D3 n7 I3 x, [1 V, K* P" g% fWend! h% ]; K \7 O' q Close #FileNo6 M, H) V( q5 N# Y, q MsgBox Text5.Text & J) U2 k. a% D( ^6 G/ \0 w& bEnd Sub 5 _$ E( k4 F, H- \0 U3 }Private Sub Command8_Click(): \/ C0 v2 q- q5 N5 N& N; G MsgBox "考拉制作!" $ I8 f! P N- J; F$ zEnd Sub $ G1 ^0 _& x: ~! A% \/ _7 CPrivate Sub Winsock1_Connect() & t, o3 T0 ~9 t8 qText4.Text = Text4.Text & "连接端口号:" & Str(Winsock1.RemotePort) & vbCrLf 8 X% t0 a+ l, N6 c7 d( ?Winsock1.Close# X$ m4 j8 n% C( j% b7 S! F PortNo = PortNo + 11 j$ `9 B# w6 f$ G+ l- |/ V If PortNo <= CLng(Text3.Text) Then" ]1 C, O. O) U' F5 Y5 w0 W" S Text4.Text = Text4.Text & vbCrLf & "已连接端口:" & PortNo! `* [! e+ f7 {# G0 E; ~; J Else5 ]' N; B$ h. @& b4 J1 B8 h' I* {3 Y Command5_Click 3 r' R$ V3 Y, m& cEnd If$ `5 L* ]( X2 \: [5 i' l End Sub ; O7 a @6 [6 W4 H5 Y3 F- tPrivate 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)9 @, I+ i5 P | Winsock1.Close . S& M; k0 b* ?+ Y1 R7 a4 \. APortNo = PortNo + 1 7 Q4 [9 x# u5 h3 B& ~If PortNo <= CLng(Text3.Text) Then0 \6 G" U- ?, |3 U% [ \ Text4.Text = Text4.Text & vbCrLf & "未连接端口:" & PortNo# q* n4 P2 d( K6 H Winsock1.Connect Text1.Text, PortNo , h! s1 S2 K) ]0 F8 SElse( _0 w7 H* @4 z' ~+ Q$ ]$ N- a Command5_Click " C6 I; q- E: K5 k/ \End If! \* R; D- b; q% p/ k1 G5 f End Sub% P8 a d6 ~( L" u; v# `4 d 0 W. T$ ~0 c) { Private Sub Command1_Click() 2 o% Z2 E7 a1 P% H% J2 UWinsock1.Protocol = sckUDPProtocol 3 F5 t; U4 K# H7 A0 xWinsock1.RemoteHost = Text1.Text 9 e6 r: Q. P( ^$ d7 q) j- k" D( _Winsock1.LocalPort = CLng(Text2.Text)& D% b+ Q3 b% S9 R9 M C Winsock1.RemotePort = CLng(Text3.Text) ; i% l) T3 r4 R6 S% ZWinsock1.Bind 5 `- u/ Y6 M7 k6 cCommand1.Enabled = False ) z1 m6 e, [- `Command2.Enabled = True- W' h) `& r: L9 M( `# M& m- ~ End Sub0 V. M4 x8 Y: l7 C Private Sub Command2_Click() 4 Q0 T0 q+ |8 p- |On Error GoTo ConnectError) ?4 }. ^, X }: B Winsock1.SendData "Koala:" & Text5.Text 1 T2 v. [9 c- _; A6 YText4.Text = "Koala:" & Text5.Text & vbCrLf & Text4.Text6 N) I& A8 k$ y1 Q# c; [ Text5.Text = "" $ p! r1 l+ C4 w5 q- tExit Sub1 S+ R! m2 F# a2 d& Z ConnectError:, q8 U7 e7 Q& I! X4 Z9 R MsgBox Error_message: i- S) U* v, Y" ^- g' ? End Sub 7 g% c }! `4 M4 g0 DPrivate Sub Command3_Click() 9 u7 o& G5 @ f& e+ d3 xMe.Hide # C) W1 l4 r t/ {7 OForm1.Show! G# z1 ^) j, v6 H/ i* ] End Sub, n- k" I! s& F1 ~% h0 e- l Private Sub Command4_Click() 5 K$ L1 h" [8 `4 \8 A. L) L/ `: uEnd0 B: Z" a/ T. h. k$ o, }4 g9 i End Sub O2 V5 e2 g3 c h; U Private Sub Text5_KeyPress(KeyAscii As Integer) 9 u9 t( W/ m( S$ R- ]) oIf KeyAscii = 13 Then2 ^5 T6 k* I- M! C& [! Z& ?( S6 k( z Command2_Click ) u5 v X0 }: N& [6 [, ~End If, G# y6 D8 |9 B8 j End Sub + C& B# X6 T; a0 s$ S) `Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)+ E+ e9 N" D! J Dim sVar As String/ H9 P D9 Y0 \# Q# ~ Winsock1.GetData sVar, vbString 8 b2 I0 \) l8 b/ W/ V) `5 @4 bText4.Text = sVar & vbCrLf & Text4.Text3 E; ~' y, r: W End Sub . Y+ p7 A( \" v: ]$ i9 \ 8 r+ _3 ^) J+ X6 [ : g% l+ ^1 m C3 _) H; p9 [ $ `5 h. M, a( r* `: c2 W1 g9 ~4 I# L, {6 [. J- k) M & H7 Q. [6 }$ P8 }
[此贴子已经被作者于2004-5-12 20:16:53编辑过]
5 F! u- Y& V! o; W6 }+ |

本版积分规则

关闭

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

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