Valhalla Legends Forums Archive | Battle.net Bot Development | [VB] Proxy Support Help

AuthorMessageTime
Spilled[DW]
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 -

[code]
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
[/code]

- My DataArrival -

[code]
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
[/code]

I am getting a result of 0. Any ideas?
September 11, 2005, 4:46 AM
HdxBmx27
[code]Result = Asc(Mid(recv, 1, 1))  'Extract value of second byte[/code]
thats your problem
Your extracting the 1st byte. Not the second, the 1st byte is always zero, so thats it.
~-~(HDX)~-~
September 11, 2005, 5:19 AM
Spilled[DW]
Ok, i fix that problem
[code]
            Result = Asc(Mid(recv, 2, 1))   'Extract value of second byte
[/code]

Now im getting  a rejected result on every proxy i try using and ive tested the proxies and they are good.
Any ideas?
September 12, 2005, 3:00 AM
Spilled[DW]
Still unsolved guys. Any ideas? Sorry about the double post didn't want to create new post to get the topic back up top.
September 13, 2005, 5:35 AM
l2k-Shadow
Did you try using "anonymous" for the username?
September 13, 2005, 6:27 AM
Spilled[DW]
How would i do that? I was told a username wasn't neccesary.
September 13, 2005, 6:33 AM
UserLoser.
[quote author=Spilled[DW] link=topic=12767.msg127976#msg127976 date=1126593204]
How would i do that? I was told a username wasn't neccesary.
[/quote]

For SOCKS4, correct.

In attempt to solve your problem, try swapping these, putting byte #4 first, then #3, #2, #1:
[code]
IP = Chr(CInt(Splt(3))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(0)))
[/code]

Or this basically does it for you:
[code]
IP = inet_addr(GetIPFromHostName(strServer))
[/code]
September 13, 2005, 12:35 PM
Spilled[DW]
[quote author=UserLoser link=topic=12767.msg127984#msg127984 date=1126614943]
[quote author=Spilled[DW] link=topic=12767.msg127976#msg127976 date=1126593204]
How would i do that? I was told a username wasn't neccesary.
[/quote]

For SOCKS4, correct.

In attempt to solve your problem, try swapping these, putting byte #4 first, then #3, #2, #1:
[code]
IP = Chr(CInt(Splt(3))) & Chr(CInt(Splt(2))) & Chr(CInt(Splt(1))) & Chr(CInt(Splt(0)))
[/code]

Or this basically does it for you:
[code]
IP = inet_addr(GetIPFromHostName(strServer))
[/code]
[/quote]
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?
September 13, 2005, 8:09 PM
UserLoser.
Using my method, still try that but do htons(57367)
September 13, 2005, 8:16 PM
Spilled[DW]
[code]
Port = Left(htons(57367), 2)
[/code]

Causes an overflow.
September 13, 2005, 8:17 PM
NetNX
1)Specifiy a username
2)I've seen this code before...
3)Try a LONG
September 14, 2005, 2:10 AM
Spilled[DW]
[quote author=NetNX link=topic=12767.msg128060#msg128060 date=1126663816]
1)Specifiy a username
2)I've seen this code before...
3)Try a LONG
[/quote]

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:
[code]
        '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
[/code]

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.?

September 14, 2005, 7:09 AM
Ringo
[quote author=Spilled[DW] link=topic=12767.msg128088#msg128088 date=1126681752]
[quote author=NetNX link=topic=12767.msg128060#msg128060 date=1126663816]
1)Specifiy a username
2)I've seen this code before...
3)Try a LONG
[/quote]

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:
[code]
        '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
[/code]

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]

Looks like the socks server is rejecting because its unable to connect to the server on the port you specifyed.
Try this:
[code]
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()
[/code]
Hope this helps
September 14, 2005, 11:27 AM
UserLoser.
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.?
[/quote]

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~):
[code]
04 01 17 e0 3f f1 53 6e cc 00
[/code]
September 14, 2005, 8:22 PM
Spilled[DW]
[quote author=UserLoser link=topic=12767.msg128122#msg128122 date=1126729365]
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.?
[/quote]

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~):
[code]
04 01 17 e0 3f f1 53 6e cc 00
[/code]
[/quote]

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.
September 14, 2005, 9:10 PM
l2k-Shadow
[code]
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
[/code]

Hope that helps.
September 14, 2005, 9:50 PM
Spilled[DW]
Ok guys got it work thanks for all your help.
[code]
       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
[/code]

Working code if anyone would like!
Thanks again
September 14, 2005, 9:51 PM
l2k-Shadow
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:

[code]
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
[/code]

EDIT: @UserLoser: good point :)
September 15, 2005, 12:50 AM
UserLoser.
[quote author=l2k-Shadow link=topic=12767.msg128175#msg128175 date=1126745412]
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:

[code]
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
[/code]
[/quote]

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
September 15, 2005, 2:02 AM
rabbit
He's right.  A WORD's maximum value is 65535






















on a 16-bit system.
September 15, 2005, 3:42 AM
Spilled[DW]
Thanks for the tip Shadow and thanks for the help again UserLoser
September 15, 2005, 5:42 AM

Search