Jump to content

gethostbyname


Deye
 Share

Recommended Posts

Hi,

i.e using $sIPAddress = TCPNameToIP("http://example.ddns.net")  got me error: 11004 WSANO_DATA

 which lead me to look for "gethostbyname"

Can  this function can be tweaked to work along giving it an address parameter ( presuming it can also work from out side IPs )
Running it locally with the private network address ..worked!

; https://www.autoitscript.com/forum/topic/165201-dllstructcreate-alignment-problem/?do=findComment&comment=1206048

Func _hostbyname($sAddress)
    TCPStartup()
    $pointer = DllCall("Ws2_32.dll", "ptr", "gethostbyname", "str", "")
    $pointer = $pointer[0]
    $hostent = DllStructCreate("ptr h_name; ptr h_aliases; short h_addrtype; short h_length;ptr h_addr_list", $pointer)
    $sh_addr_list = DllStructCreate("ptr", DllStructGetData($hostent, "h_addr_list")) ;We get the Pointer to an array of addr
    $inaddr = DllStructCreate("ptr", DllStructGetData($sh_addr_list, 1)) ;we get the array[0] ;if you want to get another index just plus 4
    $uint = DllStructGetData($inaddr, 1)
    $ret = DllCall("Ws2_32.dll", "str", "inet_ntoa", "UINT", $uint)
    Return $ret[0]
    TCPShutdown()
EndFunc   ;==>_hostbyname

 

Link to comment
Share on other sites

@Deye As mentioned by @jguinch, example.ddns.net does not exist. It is the same as trying to get god.universe's IP address

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

I take it this function maybe only good for getting the address's IP in case the requester has the same (external ip) ?

what do you get when running TCPNameToIP() against your own ddns.net which is linked to the computer you are running the command off ?

example.ddns.net is of course  fake (i.e: example)

Link to comment
Share on other sites

24 minutes ago, Deye said:

what do you get when running TCPNameToIP() against your own ddns.net which is linked to the computer you are running the command off ?

What is ddns.net?

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Your dynamic DNS address will always point towards the host computer's external IP address.

2 minutes ago, Deye said:

Anyone, please confirm do you get any ip for this address:  

You should remove http:// because its a protocol identifier used by browsers, domain names don't need any protocol to associate with.

I tried your snippet, and here is the result: 4VwG2ND.png

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...