NassauSky Posted August 26, 2023 Posted August 26, 2023 Seems with Windows 10 update the following tricks aren't working These older methods no longer work: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> $IP=InputBox("I.P. to Hostname", "Please enter the I.P. to lookup", "","", -1, -1, 0, 0) Run (@ComSpec & " /c " & "nbtstat -a " & $IP & " > " & @DesktopDir & "\Test.txt", @SystemDir, @SW_HIDE) $HostName= FileRead(@DesktopDir & "\Test.txt") MsgBox(4096,"HostName","The Host name is" & $HostName) #include <Constants.au3> $ip = "192.168.0.5" $hProcess = Run("nbtstat /A " & $ip, "", @SW_HIDE, $STDOUT_CHILD) Local $output = "" While 1 $output &= StdoutRead($hProcess) If @error Then ExitLoop Wend ConsoleWrite($output) Thanks @Emiel Wieldraaijer for what seems like an updated workaround Here is the updated method: expandcollapse popup#include <Constants.au3> Local $bShowCmdOutput = False $sIP=InputBox("I.P. to Hostname", "Please enter the I.P. to lookup", "","", -1, -1, 0, 0) ConsoleWrite("-IP " & $sIP & " hostname: " & _GetHostname($sIP) & @CRLF) Func _GetHostname($sIP) If $sIP="" Or Not _IsIPAddress($sIP) Or @error Then Exit MsgBox(64, "Blank or invalid IP address", "Cancelling Host Lookup") Local $OutputFilePath = @TempDir & "\NbtstatOutput.val" ConsoleWrite("Output File: " & $OutputFilePath & @CRLF) Local $stOldVal = DllStructCreate("dword") DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "ptr", DllStructGetPtr($stOldVal)) Local $iPID = Run(@WindowsDir & "\system32\nbtstat.exe /A " & $sIp, @TempDir, @SW_HIDE, $STDOUT_CHILD) If ProcessExists($iPID) Then ConsoleWrite ("The nbtstat process ID = " & $iPID & " please wait ..." & @CRLF) DllCall("kernel32.dll", "int", "Wow64RevertWow64FsRedirection", "ptr", DllStructGetPtr($stOldVal)) Local $sCmdOutput = "" While 1 $sCmdOutput &= StdoutRead($iPID) If @error Then ExitLoop Wend FileDelete($OutputFilePath) FileWrite($OutputFilePath, $sCmdOutput) ProcessClose($iPID) If $bShowCmdOutput Then ConsoleWrite("!------" & $sCmdOutput & @CRLF & "!------" & @CRLF) Local $HostName= FileRead($OutputFilePath) Local $aResults=StringRegExp($HostName,"(?m)^(\s{4})(.*?)\s<20>",3) If IsArray($aResults) Then Local $sOutput=$aResults[1] Else Local $sOutput="" EndIf If Not $bShowCmdOutput Then FileDelete($OutputFilePath) Return $sOutput EndFunc Func _IsIPAddress($sIP) Return StringRegExp($sIP, "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") And _ StringRegExp($sIP, "^\d{1,3}\.(?:\d{1,3}|2[0-4]\d|25[0-5])\.(?:\d{1,3}|2[0-4]\d|25[0-5])\.(?:\d{1,3}|2[0-4]\d|25[0-5])$") EndFunc Hope this helps someone. Always open to other ways of acquiring this information. Keep me posted.
Andreik Posted August 26, 2023 Posted August 26, 2023 Why not _TCPIpToName()? #include <Array.au3> #include <Inet.au3> #include <MsgBoxConstants.au3> Local $aResult, $sResult, $sIp TCPStartup() $sIp = '8.8.8.8' $aResult = _TCPIpToName($sIp, 1) If @error Then MsgBox($MB_SYSTEMMODAL, "_TCPIpToName()", "@error = " & @error & @CRLF & "@extended = " & @extended) Else _ArrayDisplay($aResult, "Local Hostname(s)") EndIf
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now