Jump to content
Sign in to follow this  

Problem using Winsock with Autoit

Recommended Posts


Hello folks!

I'm new with AutoIt and I'm facing a problem trying to find information on how can I use Winsock functions with it. I'm trying to write a function that gets the IP Address of a given url, but I don't know how can I declare the hostent structure:

struct hostent {

char FAR * h_name; /* official name of host */

char FAR * FAR * h_aliases; /* alias list */

short h_addrtype; /* host address type */

short h_length; /* length of address */

char FAR * FAR * h_addr_list; /* list of addresses */

#define h_addr h_addr_list[0]


Any help?

Edited by Cthulhu

Share this post

Link to post
Share on other sites

1. Grab the beta version

2. Look up TCPNameToIP

3. Shout "Thank you Larry" very VERY loudly. (Larry seems to do most of the TCP dev work - Apologies if I've credited the wrong person!)


Can't help you with defining struct's - I'm new to Au3 myself B) - but if all you need is the IP, the code below may help. (I used some imagination based on the _GetIP function) It's not exactly elegant, but may be a way around a problem. It requires the server to reply to Ping requests, which makes it unreliable in all circumstances:

msgbox (0, "IP of URL", _GetIPofHost("www.google.com"))

Func _GetIPofHost($hostname)
    Dim $ipinfo
    Dim $x
    Dim $y
;pipe the result of ping to file
    RunWait(@ComSpec & " /c " & "ping -n 1 " & $hostname & " > " & @TempDir & "\~i.tmp", @TempDir, @SW_HIDE)
;read and delete temp file
    $ipinfo = FileRead(@TempDir & "\~i.tmp", FileGetSize(@TempDir & "\~i.tmp"))
    FileDelete(@TempDir & "\~i.tmp")
;this next bit is nasty...needs a better Autoit user to clean up with a RegEx or something!
    $x = StringInStr($ipinfo,"[") + 1
    $y = StringInStr($ipinfo,"]") - $x
    $ipinfo = stringmid($ipinfo, $x, $y)
    Return $ipinfo

Share this post

Link to post
Share on other sites

You credit the right person for TCP

UDP is /dev/null B)

Share this post

Link to post
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
Sign in to follow this