Hello vbforums ! This is my first post here. I wanted to know how to connect my destination ip via socks4 proxy and send data via proxy. I have tried my own but i can't get it working. Why my code isn't working ? Here is rfc:
and here is my code:
Code:
SOCKS4[edit]
A typical SOCKS4 connection request looks like this:
SOCKS Client to SOCKS Server:
field 1: SOCKS version number, 1 byte, must be 0x04 for this version
field 2: command code, 1 byte:
0x01 = establish a TCP/IP stream connection
0x02 = establish a TCP/IP port binding
field 3: network byte order port number, 2 bytes
field 4: network byte order IP address, 4 bytes
field 5: the user ID string, variable length, terminated with a null (0x00)
SOCKS Server to SOCKS client:
field 1: null byte
field 2: status, 1 byte:
0x5a = request granted
0x5b = request rejected or failed
0x5c = request failed because client is not running identd (or not reachable from the server)
0x5d = request failed because client's identd could not confirm the user ID string in the request
field 3: 2 arbitrary bytes, that should be ignored
field 4: 4 arbitrary bytes, that should be ignored
This is a SOCKS4 request to connect Fred to 66.102.7.99:80, the server replies with an "OK".
Client: 0x04 | 0x01 | 0x00 0x50 | 0x42 0x66 0x07 0x63 | 0x46 0x72 0x65 0x64 0x00
The last field is 'Fred' in ASCII, followed by a null byte.
Server: 0x00 | 0x5a | 0xXX 0xXX | 0xXX 0xXX 0xXX 0xXX
0xXX can be any byte value. The SOCKS4 protocol specifies the values of these bytes should be ignored.
From this point onwards, any data sent from the SOCKS client to the SOCKS server is relayed to 66.102.7.99, and vice versa.
The command field may be 0x01 for "connect" or 0x02 for "bind"; the "bind" command allows incoming connections for protocols such as active FTP.
Code:
Dim DestServer As String
Dim DestPort As Long
Private Sub Command1_Click()
Winsock.Connect "PxoyserverIP", 1080
End Sub
Private Sub Form_Load()
DestServer = "123.123.123.123"
DestPort = 1234
End Sub
Private Sub Winsock_Close()
text1.Text = text1.Text & " close: " & vbCrLf
End Sub
Sub Winsock_Connect()
ProxyGranted = False
Dim ProxySplit() As String, ProxyHash As String, arrIndex As Integer, PortHash As String
'
ProxySplit() = Split(DestServer, ".")
For arrIndex = 0 To UBound(ProxySplit)
ProxyHash = ProxyHash & Chr$(CInt(ProxySplit(arrIndex)))
Next arrIndex
'hash ip
PortHash = Hex(DestPort)
ProxyHash = Chr$("&H" & Left$(PortHash, 2)) & Chr$("&H" & Mid$(PortHash, 3, 2)) & ProxyHash
'hash port
Winsock.SendData Chr$(&H4) & Chr$(&H1) & ProxyHash & Chr$(&H0)
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim dataString As String
Winsock.GetData dataString
If Not ProxyGranted Then
Dim VerificationCode As Byte
VerificationCode = Asc(Mid$(dataString, 2, 1))
'
If Asc(Left$(dataString, 1)) = 0 And Left$(VerificationCode, 1) = 9 And Right$(VerificationCode, 1) = 0 Then
ProxyGranted = True
text1.Text = text1.Text & " ProxyGranted: " & ProxyGranted & vbCrLf
Else
'denied
End If
Else
text1.Text = text1.Text & dataString & vbCrLf
End If
End Sub
Private Sub Winsock_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)
text1.Text = text1.Text & " err Description: " & Description & vbCrLf
End Sub