Sign in to follow this  
Followers 0

Find Local Computername by Local IP

8 posts in this topic

Posted

Hey!

I made a small script that tells me which PCs in my factory's network are online.

Now i need to get the Computer name to a specific ip!

I know that it works with CMD:

nslookup %IP%

But i need / want a similar function for autoit..

I know i could use this cmd command in autoit but i just want to get the PC name and nslookup gives some more things back...

Anybody knows such a function?

Share this post


Link to post
Share on other sites



Posted

TCPNameToIP()

Share this post


Link to post
Share on other sites

Posted (edited)

No the other way! :graduated:

#include <iNet.au3>

(EDIT) TCPStartup ( )

$test = _TCPIpToName ( "192.168.40.56" )

ConsoleWrite( $test )

Returns nothing

*facepalm

Edited by jWalker

Share this post


Link to post
Share on other sites

Posted (edited)

Try this:

#include <Constants.au3>
Global $ip = @IPAddress1
MsgBox(0, "Test", IP2HOST($ip))

Func IP2HOST($ip) ;coded by UEZ 2011
    Local $run = Run(@ComSpec & " /c ping -a -n 1 -4 " & $ip, @SystemDir, @SW_HIDE, $STDOUT_CHILD)
    Local $line
    While 1
        $line &= StdoutRead($run)
        If @error Then ExitLoop
    Wend
    Local $aResult = StringRegExp($line, "(?Um).*\h(.*)\h\[.*", 3)
    If @error Then Return SetError(1, 0, 0)
    Return $aResult[0]
EndFunc

Br,

UEZ

Edited by UEZ

Share this post


Link to post
Share on other sites

Posted

Thanks for That UEZ But

#include <iNet.au3>

(EDIT) TCPStartup ( )

$test = _TCPIpToName ( "192.168.40.56" )

ConsoleWrite( $test )

This works too.. i simply forgot TCPStartup()

Share this post


Link to post
Share on other sites

Posted

Thanks UEZ adding to my function folder :graduated:

Share this post


Link to post
Share on other sites

Posted (edited)

ping -a -n 1 -4 " & $ip

That only seems to work for the local machine for me (using XP Pro SP3).

On remote machines, "ping -a" just outputs "Pinging 192.168.0.5 ...", with no name resolution.

I can ping those same machines using their hostname, instead of IP, with no problem.

What is the -4 parm?

The other _TCPIpToName() method seems to work, but if you scan a range with it, it takes forever to return.

Non-existant IP's aren't handled very quickly. I cancelled a half-complete 0 to 255 scan after 10 minutes.

Edit: the -w option can get Ping chewing through the bad IP's quickly, but, as I said, Ping -a only returns names for the local machine or websites. DHCP is turned off on our switch and we're all using static IP's, but I can still ping successfully using the hostnames.

Edited by Spiff59

Share this post


Link to post
Share on other sites

Posted (edited)

That only seems to work for the local machine for me (using XP Pro SP3).

On remote machines, &quot;ping -a&quot; just outputs &quot;Pinging 192.168.0.5 ...&quot;, with no name resolution.

I can ping those same machines using their hostname, instead of IP, with no problem.

What is the -4 parm?

The other _TCPIpToName() method seems to work, but if you scan a range with it, it takes forever to return.

Scanning 0 to 255 took almost 10 minutes!

Hi Spiff59,

this is just an alternative to the build-in TCPNameToIP() function. Of course any name resolution (DNS, WINS,Hosts, Computer Browser) must work to resolve the ip address to host name.

My test system is Win7 X64 (joined to a DNS integrated AD domain) and thus some options in the ping.exe app might be different.

Here the ping options on my system

Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name

Options:
    -t             Ping the specified host until stopped.
                   To see statistics and continue - type Control-Break;
                   To stop - type Control-C.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -l size        Send buffer size.
    -f             Set Don't Fragment flag in packet (IPv4-only).
    -i TTL         Time To Live.
    -v TOS         Type Of Service (IPv4-only. This setting has been deprecated
                   and has no effect on the type of service field in the IP Header).
    -r count       Record route for count hops (IPv4-only).
    -s count       Timestamp for count hops (IPv4-only).
    -j host-list   Loose source route along host-list (IPv4-only).
    -k host-list   Strict source route along host-list (IPv4-only).
    -w timeout     Timeout in milliseconds to wait for each reply.
    -R             Use routing header to test reverse route also (IPv6-only).
    -S srcaddr     Source address to use.
    -4             Force using IPv4.
    -6             Force using IPv6.

Br,

UEZ

Edited by UEZ

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  
Followers 0