Adding proxy support to my bot i have ran into a problem, I am using the tutorial that Pianka wrote but i keep getting an unknown response.
Heres my Code:
- My Initiation Packet -
ElseIf UseProxy = True Then
'We will assume that this connection is for uswest.battle.net
'on port 6112, although these variables are easy to change
Dim Send As String, Port As String * 2
Dim IP As String * 4, Splt() As String
Send = Chr(&H4) 'Our first byte, the version
Send = Send & Chr(&H1) 'Our second byte, the command
'CopyMemory Port, htons(6112), 2
Port = Left(htons(6112), 2)
Send = Send & Port 'Next two bytes, the port
Splt() = Split(GetIPFromHostName(strServer), ".")
IP = Chr(CInt(Splt(0))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(3)))
Send = Send & IP 'Next four bytes, the IP of "uswest.battle.net"
Send = Send & Chr(&H0) 'Last null terminating byte for the username that we aren't using
wSock.SendData Send 'Sending the initiation packet
End If
- My DataArrival -
Dim recv As String
Dim Result As Integer
wSock.GetData recv 'Get data from socket
Result = Asc(Mid(recv, 1, 1)) 'Extract value of second byte
Select Case Result
Case &H5A
'Request granted
MsgBox "Request granted!"
Case &H5B
'Request rejected or failed
MsgBox "rejected!"
Case &H5C
'Request rejected because server cannot connect to identd on the client
MsgBox "Server rejected!"
Case &H5D
'Request rejected because usernames did not match
MsgBox "Username rejected!"
Case Else
'Unknown response (probably rejected)
MsgBox "Unknown response!"
End Select
I am getting a result of 0. Any ideas?
Result = Asc(Mid(recv, 1, 1)) 'Extract value of second byte
thats your problem
Your extracting the 1st byte. Not the second, the 1st byte is always zero, so thats it.
~-~(HDX)~-~
Ok, i fix that problem
Result = Asc(Mid(recv, 2, 1)) 'Extract value of second byte
Now im getting a rejected result on every proxy i try using and ive tested the proxies and they are good.
Any ideas?
Still unsolved guys. Any ideas? Sorry about the double post didn't want to create new post to get the topic back up top.
Did you try using "anonymous" for the username?
How would i do that? I was told a username wasn't neccesary.
Quote from: Spilled[DW] on September 13, 2005, 01:33 AM
How would i do that? I was told a username wasn't neccesary.
For SOCKS4, correct.
In attempt to solve your problem, try swapping these, putting byte #4 first, then #3, #2, #1:
IP = Chr(CInt(Splt(3))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(0)))
Or this basically does it for you:
IP = inet_addr(GetIPFromHostName(strServer))
Quote from: UserLoser on September 13, 2005, 07:35 AM
Quote from: Spilled[DW] on September 13, 2005, 01:33 AM
How would i do that? I was told a username wasn't neccesary.
For SOCKS4, correct.
In attempt to solve your problem, try swapping these, putting byte #4 first, then #3, #2, #1:
IP = Chr(CInt(Splt(3))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(0)))
Or this basically does it for you:
IP = inet_addr(GetIPFromHostName(strServer))
Hrmm, i tried swapping the byte's as you said, but still unsuccessful and ive tried multiple proxies. Knowing they are still alive. Any more ideas userloser?
Using my method, still try that but do htons(57367)
Port = Left(htons(57367), 2)
Causes an overflow.
1)Specifiy a username
2)I've seen this code before...
3)Try a LONG
Quote from: NetNX on September 13, 2005, 09:10 PM
1)Specifiy a username
2)I've seen this code before...
3)Try a LONG
Ive changed port variable to long and tried that before. Still causing an overflow when i use htons(57367) like UserLoser said.
Any more ideas? I appreciate the help so far!
Edit:
Current Initiation packet coding:
'We will assume that this connection is for uswest.battle.net
'on port 6112, although these variables are easy to change
Dim Send As String, Port As String * 2
Dim IP As String * 4, Splt() As String
Send = Chr(&H4) 'Our first byte, the version
Send = Send & Chr(&H1) 'Our second byte, the command
'CopyMemory Port, htons(6112), 2
Port = Left(htons(57367), 2)
Send = Send & Port 'Next two bytes, the port
Splt() = Split(GetIPFromHostName(strServer), ".")
IP = Chr(CInt(Splt(3))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(0)))
'IP = Chr(CInt(Splt(0))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(3)))
Send = Send & IP 'Next four bytes, the IP of "uswest.battle.net"
Send = Send & Chr(&H0) 'Last null terminating byte for the username that we aren't using
wSock.SendData Send 'Sending the initiation packet
Packet Log when i use htons(6112)
1 Hide Hide 9 Send
0000 04 01 2D 38 6E 53 F1 3F 00 ..-8nS.?.
2 Hide Hide 8 Recv
0000 00 5B 2D 38 6E 53 F1 3F .[-8nS.?
Quote from: Spilled[DW] on September 14, 2005, 02:09 AM
Quote from: NetNX on September 13, 2005, 09:10 PM
1)Specifiy a username
2)I've seen this code before...
3)Try a LONG
Ive changed port variable to long and tried that before. Still causing an overflow when i use htons(57367) like UserLoser said.
Any more ideas? I appreciate the help so far!
Edit:
Current Initiation packet coding:
'We will assume that this connection is for uswest.battle.net
'on port 6112, although these variables are easy to change
Dim Send As String, Port As String * 2
Dim IP As String * 4, Splt() As String
Send = Chr(&H4) 'Our first byte, the version
Send = Send & Chr(&H1) 'Our second byte, the command
'CopyMemory Port, htons(6112), 2
Port = Left(htons(57367), 2)
Send = Send & Port 'Next two bytes, the port
Splt() = Split(GetIPFromHostName(strServer), ".")
IP = Chr(CInt(Splt(3))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(0)))
'IP = Chr(CInt(Splt(0))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(3)))
Send = Send & IP 'Next four bytes, the IP of "uswest.battle.net"
Send = Send & Chr(&H0) 'Last null terminating byte for the username that we aren't using
wSock.SendData Send 'Sending the initiation packet
Packet Log when i use htons(6112)
1 Hide Hide 9 Send
0000 04 01 2D 38 6E 53 F1 3F 00 ..-8nS.?.
2 Hide Hide 8 Recv
0000 00 5B 2D 38 6E 53 F1 3F .[-8nS.?
Looks like the socks server is rejecting because its unable to connect to the server on the port you specifyed.
Try this:
Dim i As Long, SP() As String, tmpPort As String, tmpP As String
SP = Split("213.248.106.204", ".")
tmpPort = Right("0000" & Hex(6112), 4)
For i = 0 To UBound(SP)
If i = 0 Then
tmpP = MakeWORD(&H104) 'chr(4) & chr(1)
tmpP = tmpP & Chr(Val("&H" & Mid(tmpPort, 1, 2))) & _
Chr(Val("&H" & Mid(tmpPort, 3, 2)))
End If
tmpP = tmpP & CStr(Chr(SP(i)))
Next i
tmpP = tmpP & Chr(0)
Ws1.SendData tmpP
Erase SP()
Hope this helps
Heh, I don't get what the big deal is.. All you need is inet_addr and htons. You're doing unnecessary stuff.
Quote
Packet Log when i use htons(6112)
1 Hide Hide 9 Send
0000 04 01 2D 38 6E 53 F1 3F 00 ..-8nS.?.
2 Hide Hide 8 Recv
0000 00 5B 2D 38 6E 53 F1 3F .[-8nS.?
Correct me if I'm wrong, but it should be (that's what I'm getting, but it's untested, so hardcode this byte array and send it~):
04 01 17 e0 3f f1 53 6e cc 00
Quote from: UserLoser on September 14, 2005, 03:22 PM
Heh, I don't get what the big deal is.. All you need is inet_addr and htons. You're doing unnecessary stuff.
Quote
Packet Log when i use htons(6112)
1 Hide Hide 9 Send
0000 04 01 2D 38 6E 53 F1 3F 00 ..-8nS.?.
2 Hide Hide 8 Recv
0000 00 5B 2D 38 6E 53 F1 3F .[-8nS.?
Correct me if I'm wrong, but it should be (that's what I'm getting, but it's untested, so hardcode this byte array and send it~):
04 01 17 e0 3f f1 53 6e cc 00
hrm, htons(6112) is returning me -8169.... i dont think that is correct..... any ideas on that?
i Can hardcore the byte array you have provided Userloser but the 2 bytes of htons(6112) is always different then yours.
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal numbytes As Long)
Private Declare Function htons Lib "ws2_32" (ByVal hostshort As Long) As Integer
Public Function GetPortString(Port As Long) As String
Dim tmpPort As Integer, Output As String * 2
tmpPort = htons(Port)
CopyMemory ByVal Output, tmpPort, 2
GetPortString = Output
End Function
Hope that helps.
Ok guys got it work thanks for all your help.
Dim Send As String, Port As String * 2
Dim IP As String * 4, Splt() As String
Send = Chr(&H4)
Send = Send & Chr(&H1)
CopyMemory ByVal Port, htons(6112), 2
Send = Send & Port 'Next two bytes, the port
Splt() = Split(GetIPFromHostName(strServer), ".")
IP = Chr(CInt(Splt(0))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(3)))
Send = Send & IP
Send = Send & Chr(&H0)
wSock.SendData Send
Working code if anyone would like!
Thanks again
For future reference, if you wish not to use API to get the port (don't know why but yeah some people prefer that), the function would look something like this:
Public Function GetPortString(Port As Long) As String
Dim s As String
s = Hex(Port)
Select Case Len(s)
Case 1, 2
GetPortString = Chr$(0) & Chr$(CLng("&H" & s))
Case 3
GetPortString = Chr$(CLng("&H" & Left$(s, 1))) & Chr$(CLng("&H" & Mid$(s, 2, 2)))
Case 4
GetPortString = Chr$(CLng("&H" & Left$(s, 2))) & Chr$(CLng("&H" & Mid$(s, 3, 2)))
Case Else
MsgBox "Port value is too high. The maximum value for a Port is the maximum value of a 16-bit integer (65535)."
End Select
End Function
EDIT: @UserLoser: good point :)
Quote from: l2k-Shadow on September 14, 2005, 07:50 PM
For future reference, if you wish not to use API to get the port (don't know why but yeah some people prefer that), the function would look something like this:
Public Function GetPortString(Port As Long) As String
Dim s As String
s = Hex(Port)
Select Case Len(s)
Case 1, 2
GetPortString = Chr$(0) & Chr$(CLng("&H" & s))
Case 3
GetPortString = Chr$(CLng("&H" & Left$(s, 1))) & Chr$(CLng("&H" & Mid$(s, 2, 2)))
Case 4
GetPortString = Chr$(CLng("&H" & Left$(s, 2))) & Chr$(CLng("&H" & Mid$(s, 3, 2)))
Case Else
MsgBox "Port value is too high. The maximum value for a Port is the maximum value of a WORD (65535)."
End Select
End Function
Some might argue that the maximum value of a WORD isn't necessarly 65535, so you might want to edit that to say 16-bit integer :P
He's right. A WORD's maximum value is 65535
on a 16-bit system.
Thanks for the tip Shadow and thanks for the help again UserLoser