Jump to content

Get connected IPadres from Inetread


nend
 Share

Recommended Posts

Hi,

I have made small program which is collecting data from a device on my local network by using inetread.
This devive uses mDNS and can be approached by using this adres "http://name.local", this works ok.
Can I find what's the IPadress from this device by using Inetread, to use every it's collecting data, by using mDNS everytime it's slow and I want to use the IPadres after the first time connecting.
If there is a other sollution to get the IPadres of a device using mDNS.
I've search a long time for it but can't find a working sample in AutoIT how collect the IPAdres from a mDNS/Bonjour device.

Link to comment
Share on other sites

Since you are dealing with the HTTP protocol, if you aren't inextricably tied to using InetRead(), then you could easily replace InetRead with a simple CURL command.  In order to retrieve the HTTP request content and/or get the remote IP address, you could run the following command and capture the stdout output:

;The following line will get the http response and the remote IP address
curl -sL -w "\r\nRemote IP = %{remote_ip}\r\n" http://name.local

or 

;The following line will just get the remote IP address
curl -sL -o nul -w "\r\nRemote IP = %{remote_ip}\r\n" http://name.local

The remote IP address will be appended to the end of the output on a separate line.

Once you download the 32-bit and/or 64-bit CURL for Windows executable, you can open a command console and run the  commands to see the output for yourself.  Then you can translate the running and capturing of the command and its output into an AutoIt script.

FYI:
The above curl command's parameters are:
-s = run silent, no progress info
-L = Follow redirects (not really necessary in your case, but useful otherwise)
-o = Write the response output to the following file
-w = Write the following string to the output

If you need more information on CURL, read the CURL Documentation.

 

Edited by TheXman
Link to comment
Share on other sites

17 minutes ago, pseakins said:

I assign each device on my local network a fixed IP via static lease DHCP settings in my router. Do this, then you can just hard code the address and forget about it.

Not all routers have an option to reserve an IP address in it's DHCP server.

Link to comment
Share on other sites

@TheXman, thanks for the reply but I want it in AutoIt code.
I found a link which made it possible but it  has a lot of functions which I don't need so I striped the UDF and made a new one from it
Link from the "DIG" from which I made this UDF 


I attach it if some one needs it, It's only returning the IPadres of the mDNS/bonjour device.
 

ConsoleWrite(_mDNS("http://Diskstation.local") & @CRLF)

Func _mDNS($domain)
    Local $return_ip, $domain_convert, $mDNS_msg

    $domain = StringReplace($domain , "http://", "")
    Local $domain_array = StringSplit($domain, ".")
    For $i = 1 To $domain_array[0]
        $domain_convert = $domain_convert & Hex(BinaryLen($domain_array[$i]), 2) & StringTrimLeft(StringToBinary($domain_array[$i]), 2)
    Next

    UDPStartup()

    Local $mDNS_sock = UDPOpen("224.0.0.251", 5353)
    If @error Then
        UDPShutdown()
        SetError(1)
        Return ""
    EndIf

    Local $query_time = TimerInit()

    UDPSend($mDNS_sock, "0x5A8901000001000000000000" & $domain_convert & "0000010001")

    Do
        $mDNS_msg = UDPRecv($mDNS_sock, 512, 1)
        Sleep(100)
    Until $mDNS_msg <> "" Or TimerDiff($query_time) > 1000

    UDPShutdown()

    For $i = 3 To 0 Step -1
        $return_ip = $return_ip & Dec(StringMid(BinaryMid($mDNS_msg, BinaryLen($mDNS_msg) - $i, 1), 3))
        If $i <> 0 Then
            $return_ip = $return_ip & "."
        EndIf
    Next

    Return $return_ip
EndFunc


 

Edited by nend
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...