Find Local Computername by Local IP
#1
Posted 19 October 2011 - 09:22 AM
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
Posted 19 October 2011 - 09:48 AM
#3
Posted 19 October 2011 - 09:50 AM
#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
Posted 19 October 2011 - 12:08 PM
#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
Posted 19 October 2011 - 12:16 PM
#include <iNet.au3>
(EDIT) TCPStartup ( )
$test = _TCPIpToName ( "192.168.40.56" )
ConsoleWrite( $test )
This works too.. i simply forgot TCPStartup()
#6
Posted 19 October 2011 - 12:27 PM
Example List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _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() • _StringIsValid() • _StringReplaceWholeWord() • _StringStripChar() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • AutoIt Search • AutoIt3 Portable • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • FileInstallr • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIGetBkColor() • LockFile() • PasteBin • SciTE Jump • Signature Creator • WM_COPYDATA • More Examples...Updated: 11/04/2013
#7
Posted 19 October 2011 - 02:26 PM
That only seems to work for the local machine for me (using XP Pro SP3).ping -a -n 1 -4 " & $ip
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
Posted 19 October 2011 - 02:37 PM
Hi Spiff59,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.
Scanning 0 to 255 took almost 10 minutes!
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, 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




