Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Find Local Computername by Local IP


  • Please log in to reply
7 replies to this topic

#1 jWalker

jWalker

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 19 October 2011 - 09:22 AM

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?







#2 AdmiralAlkex

AdmiralAlkex

    Here be dragons

  • Active Members
  • PipPipPipPipPipPip
  • 4,607 posts

Posted 19 October 2011 - 09:48 AM

TCPNameToIP()

#3 jWalker

jWalker

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 19 October 2011 - 09:50 AM

No the other way! :graduated:


#include <iNet.au3>

(EDIT) TCPStartup ( )

$test = _TCPIpToName ( "192.168.40.56" )
ConsoleWrite( $test )

Returns nothing



*facepalm

Edited by jWalker, 19 October 2011 - 09:57 AM.


#4 UEZ

UEZ

    Never say never

  • MVPs
  • 4,492 posts

Posted 19 October 2011 - 12:08 PM

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, 19 October 2011 - 02:25 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#5 jWalker

jWalker

    Wayfarer

  • Active Members
  • Pip
  • 95 posts

Posted 19 October 2011 - 12:16 PM

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()

#6 guinness

guinness

    I've a handle on the fiction

  • Developers
  • 15,704 posts

Posted 19 October 2011 - 12:27 PM

Thanks UEZ adding to my function folder :graduated:

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasswordValidPasteBinPosts Per DayPreExpandQueue()SciTE JumpSHELLHOOKShunting-YardSignature CreatorStack()StringAddLF()/StringStripLF()StringEOLToCRLF()WM_COPYDATAMore Examples...
Updated: 12/04/2014


#7 Spiff59

Spiff59

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,342 posts

Posted 19 October 2011 - 02:26 PM

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, 19 October 2011 - 02:45 PM.


#8 UEZ

UEZ

    Never say never

  • MVPs
  • 4,492 posts

Posted 19 October 2011 - 02:37 PM

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
Plain Text         
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, 19 October 2011 - 02:44 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users