Valhalla Legends Forums Archive | Battle.net Bot Development | Some questions Concerning Socks4/5 Proxies - Update #1

AuthorMessageTime
BaDDBLooD
How do you send the Address/Port you want to connect to?

Example:

Socks 4 Proxy

I want to connect to USEast.Battle.Net:6112

Thanks!
September 19, 2004, 6:09 PM
UserLoser.
Look here


You'll have to resolve useast.battle.net to an IP, then using a function such as inet_addr(), you can convert the dotted string, IP address into a 4 byte value. Using htons() may be useful also for converting the port into a 2 byte value.
September 19, 2004, 6:29 PM
BaDDBLooD
Thanks, the api calls was what i needed.

EDIT:

When i connect to a proxy, this is what i am sending

[code]

Chr(&H4) & Chr(&H1) & htons("6112") & inet_addr(Bot.Server) & "anonymous" & Chr(&H0)

[/code]

Using These:

[code]

Public Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long
Public Declare Function htons Lib "wsock32.dll" (ByVal hostshort As Long) As Integer

[/code]

This is what it looks like:

[code]

[1:54:22 PM] 0000: 04 01 2D 38 31 36 39 2D 32 31 30 30 36 32 39 34 -8169-21006294
0010: 34 31 61 6E 6F 6E 79 6D 6F 75 73 00 41anonymous.....

[/code]

That doesn't look right, does it?
September 19, 2004, 6:34 PM
LordNevar
Here this my make it easier for ya.

This is my API call.

[code]
Public Declare Function gethostbyname Lib "wsock32" _
(ByVal hostname As String) As Long
[/code]

Here's my decode.

[code]
Public Function GetIPFromHostName(ByVal sHostName As String) As String
Dim nbytes As Long
Dim ptrHosent As Long
Dim ptrName As Long
Dim ptrAddress As Long
Dim ptrIPAddress As Long
Dim sAddress As String

sAddress = Space$(4)
DoEvents
ptrHosent = gethostbyname(sHostName & vbNullChar)

If ptrHosent <> 0 Then
ptrAddress = ptrHosent + 12

CopyMemory ptrAddress, ByVal ptrAddress, 4
CopyMemory ptrIPAddress, ByVal ptrAddress, 4
CopyMemory ByVal sAddress, ByVal ptrIPAddress, 4
GetIPFromHostName = IPToText(sAddress)
End If
End Function

Private Function IPToText(ByVal IPAddress As String) As String
IPToText = CStr(Asc(IPAddress)) & "." & _
CStr(Asc(Mid$(IPAddress, 2, 1))) & "." & _
CStr(Asc(Mid$(IPAddress, 3, 1))) & "." & _
CStr(Asc(Mid$(IPAddress, 4, 1)))
End Function
[/code]

Forgot who the original author was or where I got this from, but thanxs to whoever it was.
September 19, 2004, 7:28 PM
BaDDBLooD
I Just wanted to know how to send the Remote IP Address/Port for the proxy to connect to. Thanks for that tidbit though.
September 19, 2004, 7:59 PM
St0rm.iD
Looks to me like you're sending it in ascii instead of binary.
September 19, 2004, 8:17 PM
BaDDBLooD
Thanks for the info, unfortunately i did not comprehend what you just said!
September 19, 2004, 8:28 PM
shadypalm88
[quote author=BaDDBLooD link=board=17;threadid=8743;start=0#msg80903 date=1095623978]
I Just wanted to know how to send the Remote IP Address/Port for the proxy to connect to. Thanks for that tidbit though.
[/quote][code]Chr(&H4) & Chr(&H1) & htons("6112") & inet_addr(Bot.Server) & "anonymous" & Chr(&H0)[/code]This was right for the most part. There's one big problem with it, however. inet_addr converts a readable IP address (e.g. 127.0.0.1) to its 4-byte machine readable form. It will choke on a domain name like useast.battle.net. To do this, you have to use something like the function LordNevar posted, only don't run it through IPToText. For IP addresses, you should still use inet_addr.

You can use something like this to check if a given address is an IP:[code]'Checks if the given address is a dotted-quad
'IP by seeing if the string only contains
'periods (.) and numbers.
Public Function IsIPAddress(Address As String) As Boolean
Dim i&, a%
IsIPAddress = False
For i = 1 To Len(Address)
a = Asc(Mid$(Address, 1, 1))
If (a <> 46) And ((a > 57) Or (a < 48)) Then _
Exit Function
Next i
IsIPAddress = True
End Function[/code]

P.S. htons("6112") Only put a number in quotes if you are going to be directly displaying it to the user. If you ever want to get into strongly-typed languages (e.g. C, C++, Java) you'll have to break that habit.
September 19, 2004, 8:42 PM
BaDDBLooD
Shady you think we could talk on aim?
September 19, 2004, 8:48 PM
shadypalm88
[quote author=BaDDBLooD link=board=17;threadid=8743;start=0#msg80921 date=1095626934]
Shady you think we could talk on aim?
[/quote]Alright; my name's in my profile.
September 19, 2004, 8:52 PM
UserLoser.
[quote author=BaDDBLooD link=board=17;threadid=8743;start=0#msg80879 date=1095618850]
That doesn't look right, does it?
[/quote]

Use RtlMoveMemory, convert the result of htons() to two bytes, along with result of inet_addr to 4 bytes, don't insert the value as a string
September 19, 2004, 9:00 PM
UserLoser.
[quote author=shadypalm88 link=board=17;threadid=8743;start=0#msg80919 date=1095626564]
[quote author=BaDDBLooD link=board=17;threadid=8743;start=0#msg80903 date=1095623978]
I Just wanted to know how to send the Remote IP Address/Port for the proxy to connect to. Thanks for that tidbit though.
[/quote][code]Chr(&H4) & Chr(&H1) & htons("6112") & inet_addr(Bot.Server) & "anonymous" & Chr(&H0)[/code]This was right for the most part. There's one big problem with it, however. inet_addr converts a readable IP address (e.g. 127.0.0.1) to its 4-byte machine readable form. It will choke on a domain name like useast.battle.net. To do this, you have to use something like the function LordNevar posted, only don't run it through IPToText. For IP addresses, you should still use inet_addr.

You can use something like this to check if a given address is an IP:[code]'Checks if the given address is a dotted-quad
'IP by seeing if the string only contains
'periods (.) and numbers.
Public Function IsIPAddress(Address As String) As Boolean
Dim i&, a%
IsIPAddress = False
For i = 1 To Len(Address)
a = Asc(Mid$(Address, 1, 1))
If (a <> 46) And ((a > 57) Or (a < 48)) Then _
Exit Function
Next i
IsIPAddress = True
End Function[/code]

P.S. htons("6112") Only put a number in quotes if you are going to be directly displaying it to the user. If you ever want to get into strongly-typed languages (e.g. C, C++, Java) you'll have to break that habit.
[/quote]

Note that inet_addr will return INADDR_NONE (0xFFFFFFFF) if the value given is not a valid IP address
September 19, 2004, 9:02 PM
BaDDBLooD
Thanks everyone, got it working!
September 19, 2004, 9:33 PM

Search