Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: BaDDBLooD on September 19, 2004, 01:09 PM

Title: Some questions Concerning Socks4/5 Proxies - Update #1
Post by: BaDDBLooD on September 19, 2004, 01:09 PM
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!
Title: Re:Some questions Concerning Socks4/5 Proxies
Post by: UserLoser. on September 19, 2004, 01:29 PM
Look here
(http://forum.valhallalegends.com/phpbbs/index.php?action=display;board=17;threadid=8732;start=0#msg80786)

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.
Title: Re:Some questions Concerning Socks4/5 Proxies
Post by: BaDDBLooD on September 19, 2004, 01:34 PM
Thanks, the api calls was what i needed.

EDIT:

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



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



Using These:



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



This is what it looks like:



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



That doesn't look right, does it?
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: LordNevar on September 19, 2004, 02:28 PM
Here this my make it easier for ya.

This is my API call.


Public Declare Function gethostbyname Lib "wsock32" _
 (ByVal hostname As String) As Long


Here's my decode.


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


Forgot who the original author was or where I got this from, but thanxs to whoever it was.
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: BaDDBLooD on September 19, 2004, 02:59 PM
I Just wanted to know how to send the Remote IP Address/Port for the proxy to connect to.  Thanks for that tidbit though.
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: Banana fanna fo fanna on September 19, 2004, 03:17 PM
Looks to me like you're sending it in ascii instead of binary.
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: BaDDBLooD on September 19, 2004, 03:28 PM
Thanks for the info, unfortunately i did not comprehend what you just said!
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: shadypalm88 on September 19, 2004, 03:42 PM
Quote from: BaDDBLooD on September 19, 2004, 02:59 PM
I Just wanted to know how to send the Remote IP Address/Port for the proxy to connect to.  Thanks for that tidbit though.
Chr(&H4) & Chr(&H1) & htons("6112") & inet_addr(Bot.Server) & "anonymous" & Chr(&H0)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:'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


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.
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: BaDDBLooD on September 19, 2004, 03:48 PM
Shady you think we could talk on aim?
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: shadypalm88 on September 19, 2004, 03:52 PM
Quote from: BaDDBLooD on September 19, 2004, 03:48 PM
Shady you think we could talk on aim?
Alright; my name's in my profile.
Title: Re:Some questions Concerning Socks4/5 Proxies
Post by: UserLoser. on September 19, 2004, 04:00 PM
Quote from: BaDDBLooD on September 19, 2004, 01:34 PM
That doesn't look right, does it?

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
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: UserLoser. on September 19, 2004, 04:02 PM
Quote from: shadypalm88 on September 19, 2004, 03:42 PM
Quote from: BaDDBLooD on September 19, 2004, 02:59 PM
I Just wanted to know how to send the Remote IP Address/Port for the proxy to connect to.  Thanks for that tidbit though.
Chr(&H4) & Chr(&H1) & htons("6112") & inet_addr(Bot.Server) & "anonymous" & Chr(&H0)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:'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


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.

Note that inet_addr will return INADDR_NONE (0xFFFFFFFF) if the value given is not a valid IP address
Title: Re:Some questions Concerning Socks4/5 Proxies - Update #1
Post by: BaDDBLooD on September 19, 2004, 04:33 PM
Thanks everyone, got it working!