strIP = Asc(Mid(strTempData, 1, 1)) & "." & _
Asc(Mid(strTempData, 2, 1)) & "." & _
Asc(Mid(strTempData, 3, 1)) & "." & _
Asc(Mid(strTempData, 4, 1))
I suggest using a function, as this is done in many packets, if I'm correct. Its also used in proxy handling, which many bots have.
Public Function DWORDtoIP(DWORD as Long) as String
Dim IP as String * 11
For i = 1 to 4
IP = IP and Asc(Mid(DWORD, i, 1)
Next i
DWORDtoIP = IP
End Function
Public Function IPtoDWORD(IP as Long) as Long
Dim DWORD as String * 4, Splt(0 to 4) as String
Splt = Split(IP, ".")
For i = 1 to 4
DWORD = DWORD and Chr(CLng(Splt(i)))
Next i
IPtoDWORD = CLng(DWORD)
End Function
Just use inet_addr and inet_ntoa instead of using much less efficient vb code
Example:
inet_addr(255.255.255.255) = 0xffffffff
unsigned long addr = 0x12345678;
inet_ntoa(*(struct in_addr*)&addr)) = 120.86.52.18
Huh? Mind posting a VB code snippet to call the C++ function or whatever it is?
inet_addr (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/inet_addr_2.asp)()
inet_ntoa (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/inet_ntoa_2.asp)()
Standard Windows API calls...
As a side note, inet_addr is obsolete and should not be used in new code. You should instead use inet_aton.
Not to be rude lol but can somone split this into the general forum, and re-lock it for now.
edit: This way if I ever fix anything the post is not like 3 pages away from the original info.
If I could edit my posts while the thread was locked I wouldent have asked for it to be unlocked though I think theres a limit on how much text I can add to it anyways.
The reasons I did that for the IP instead of going with eg. inet_ntoa, was to keep it as simple as possible and to show how to do this manualy (doubt there's many here familiar with the function anyways), which I was going to do with GetLong in the begining but I'm sure noone wanted to see (((b*(2^8))*(2^8))*(2^8)) etc etc etc..
Eventualy you'll probably find more things that could be done better, which should be done at your own discretion.
Quote from: l)ragon on April 15, 2005, 03:03 AM
Not to be rude lol but can somone split this into the general forum, and re-lock it for now.
I would have, but I thought you didn't want it locked at the moment. Topic split.
Quote from: MyndFyre on April 15, 2005, 03:51 AM
Quote from: l)ragon on April 15, 2005, 03:03 AM
Not to be rude lol but can somone split this into the general forum, and re-lock it for now.
I would have, but I thought you didn't want it locked at the moment. Topic split.
I was going to complete it the night of my last post to the thread, but I kept getting side tracked with other crap, and at the moment I dont have vb6 installed on this pc, and its about a 36 hour walk from here to get my cd's, so it may be awhile.
Thanks MyndFyre. Didn't mean to spark a whole big thing, just wanted to make a suggestion.
Hrm, LoRd[nK], I've never really used DLL functions before. Mind giving a bit of help here? I hope I got this right, but I don't know if I did.
Public Declare Function inet_addr Lib Ws2_32.dll (in as String)
'// inet_addr is used as an IPtoDWORD function.
Public Declare Function inet_ntoa Lib Ws2_32.dll (in as String)
'// inet_ntoa is used as a DWORDtoIP function.
Public Function IPtoDWORD(IP as String) as Long
'// This is used as a wrapper for the inet_addr function, providing an easier to remember name.
IPtoDWORD = inet_addr(IP)
End Function
Public Function DWORDtoIP(DWORD as Long) as String
'// This is used as a wrapper for the inet_ntoa function, providing an easier to remember name.
DWORDtoIP = inet_ntoa(DWORD)
End Function
Quote from: Joex86] link=topic=11287.msg108685#msg108685 date=1113599999]
Thanks MyndFyre. Didn't mean to spark a whole big thing, just wanted to make a suggestion.
Hrm, LoRd[nK], I've never really used DLL functions before. Mind giving a bit of help here? I hope I got this right, but I don't know if I did.
Public Declare Function inet_addr Lib Ws2_32.dll (in as String)
'// inet_addr is used as an IPtoDWORD function.
Public Declare Function inet_ntoa Lib Ws2_32.dll (in as String)
'// inet_ntoa is used as a DWORDtoIP function.
Public Function IPtoDWORD(IP as String) as Long
'// This is used as a wrapper for the inet_addr function, providing an easier to remember name.
IPtoDWORD = inet_addr(IP)
End Function
Public Function DWORDtoIP(DWORD as Long) as String
'// This is used as a wrapper for the inet_ntoa function, providing an easier to remember name.
DWORDtoIP = inet_ntoa(DWORD)
End Function
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Long
Private Declare Function inet_ntoa Lib "wsock32.dll" (ByVal addr As Long) As Long
Public Function DWORDtoIP(DWORD as Long) as String
'// This is used as a wrapper for the inet_ntoa function, providing an easier to remember name.
DWORDtoIP = inet_ntoa(DWORD)
End Function
That doesn't work. inet_ntoa is returning as a Long, or pointer to the string. See: lstrcpy(A/W)
Ooh, thanks. The rest works, provided I make them return longs?
EDIT: Anybody wanna explain the whole Alias thing? I think that way we would only need the wrapper for the second, when we un-pointer-ify the string.
Quote from: l)ragon on April 15, 2005, 05:50 PM
Quote from: Joex86] link=topic=11287.msg108685#msg108685 date=1113599999]
Thanks MyndFyre. Didn't mean to spark a whole big thing, just wanted to make a suggestion.
Hrm, LoRd[nK], I've never really used DLL functions before. Mind giving a bit of help here? I hope I got this right, but I don't know if I did.
Public Declare Function inet_addr Lib Ws2_32.dll (in as String)
'// inet_addr is used as an IPtoDWORD function.
Public Declare Function inet_ntoa Lib Ws2_32.dll (in as String)
'// inet_ntoa is used as a DWORDtoIP function.
Public Function IPtoDWORD(IP as String) as Long
'// This is used as a wrapper for the inet_addr function, providing an easier to remember name.
IPtoDWORD = inet_addr(IP)
End Function
Public Function DWORDtoIP(DWORD as Long) as String
'// This is used as a wrapper for the inet_ntoa function, providing an easier to remember name.
DWORDtoIP = inet_ntoa(DWORD)
End Function
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Long
Private Declare Function inet_ntoa Lib "wsock32.dll" (ByVal addr As Long) As Long
such a waste of cycles...
Quote from: Joex86] link=topic=11287.msg108722#msg108722 date=1113617829]
Ooh, thanks. The rest works, provided I make them return longs?
EDIT: Anybody wanna explain the whole Alias thing? I think that way we would only need the wrapper for the second, when we un-pointer-ify the string.
Alias allows you to define a name for your function that is something other than the export from the DLL. For example, CopyMemory is actually a declared alias of the DLL function RtlMoveMemory.