VB6 中 使用Winsock穿越各种代理的实现(TCP协议)[9]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

Public Function ProxyStep(ProxyType As Integer, PStep As Integer)
Dim SendByte() As Byte
If ProxyType = 0 Then                    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ sock4代理
If PStep = 1 Then

ReDim SendByte(0 To 8) As Byte

SendByte(0) = 4                          ' 04

SendByte(1) = 1                          ' 01

SendByte(2) = Int(DestPort / 256)

SendByte(3) = DestPort Mod 256

SendByte(4) = GetIPByte(1, DestIP)

SendByte(5) = GetIPByte(2, DestIP)

SendByte(6) = GetIPByte(3, DestIP)

SendByte(7) = GetIPByte(4, DestIP)

SendByte(8) = 0                  '最后要以 0 结束

Form1.Winsock1.SendData SendByte()

ConnStep = PStep + 1
Exit Function

End If


If PStep = 2 Then            '代理回复,第二字节为 90 为成功,其余值为失败
If Asc(Mid(RevBuffer, 2, 1)) <> 90 Then
Debug.Print Asc(Mid(RevBuffer, 2, 1))
MsgBox "连接sock4代理失败!", 48, "错误"
Form1.Winsock1.Close
ConnStep = 0
Exit Function
Else

Form1.Label8.Caption = "连接目标服务器成功!"
ConnStep = -1
Form2.Show
Exit Function
End If

End If
End If


'*******************下面的例子有大量重复代码,是为了让大家更清楚地了解sock5穿透过程,大家可以拿回去自己优化 **********************************

If ProxyType = 1 Then '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ sock5代理

Select Case PStep


Case 1
ReDim SendByte(0 To 2) As Byte   '第一步 无验证发送 05 01 00, 有验证发送 05 02 02
SendByte(0) = 5                     ' 05
SendByte(1) = 1             '01 '在有用户密码验证时此字节是 1 还是 2 有诸多争论,现以腾讯QQ穿越代理模拟器时发送的数据为准,如有错误,请自己修改!
SendByte(2) = IIf(Form1.Check1.Value = 0, 0, 2) '00 或 02
Form1.Winsock1.SendData SendByte()
ConnStep = PStep + 1
Exit Function

Case 2               '代理回复
If Asc(Mid(RevBuffer, 2, 1)) = 255 Then 'FF (255) 为失败
MsgBox "连接代理失败!", 64
Form1.Winsock1.Close
ConnStep = 0
Exit Function

End If

If Asc(Mid(RevBuffer, 2, 1)) = 0 And Asc(Mid(RevBuffer, 1, 1)) = 5 Then '若代理回复 05 00 为无验证连接成功
Form1.Label8.Caption = "连接成功!无验证"

ReDim SendByte(0 To 9) As Byte           '第二步 无验证 发送连接请求
SendByte(0) = 5
SendByte(1) = 1
SendByte(2) = 0
SendByte(3) = 1
SendByte(4) = GetIPByte(1, DestIP)
SendByte(5) = GetIPByte(2, DestIP)
SendByte(6) = GetIPByte(3, DestIP)
SendByte(7) = GetIPByte(4, DestIP)
SendByte(8) = Int(DestPort / 256)   '把10进制端口分成两个字节
SendByte(9) = DestPort Mod 256      '把10进制端口分成两个字节
Form1.Winsock1.SendData SendByte()

ConnStep = ConnStep + 1

本文关键:VB6 中 使用Winsock穿越各种代理的实现(TCP协议)
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top