Jump to content

resolve remote computername


memnon
 Share

Recommended Posts

You can use WMI to get the remote host name.

ping -a will only work when a DNS is available!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I don't know whether _TCPIpToName will work when there is no DNS/WINS available.

Here a WMI version:

 

;code by UEZ 2011

Global Const $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")
$sIP = "127.0.0.1"
MsgBox(0, "Get Host Name", "IP: " & $sIP & " -> Host Name: " &  WMI_GetHostName($sIP))

Func WMI_GetHostName($host)
    Local $HostNameWMI, $colItems, $colItem, $ping
    $ping = Ping($host)
    If $ping Then
        $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $host & "\root\cimv2")
        If @error Then Return SetError(2, 0, "")
        $colItems = $objWMIService.ExecQuery("SELECT SystemName FROM Win32_NetworkAdapter WHERE NetConnectionStatus=2", "WQL", 0x30)
        If IsObj($colItems) Then
            For $objItem In $colItems
                If $objItem.SystemName = "" Then Return SetError(3, 0, "")
                Return $objItem.SystemName
            Next
            Return $HostNameWMI
        Else
            Return SetError(3, 0, "")
        EndIf
    Else
        Return SetError(1, 0, "")
    EndIf
EndFunc


Func ObjErrorHandler()
    ConsoleWrite(   "A COM Error has occured!" & @CRLF  & @CRLF & _
                                "err.description is: "    & @TAB & $oErrorHandler.description    & @CRLF & _
                                "err.windescription:"     & @TAB & $oErrorHandler & @CRLF & _
                                "err.number is: "         & @TAB & Hex($oErrorHandler.number, 8)  & @CRLF & _
                                "err.lastdllerror is: "   & @TAB & $oErrorHandler.lastdllerror   & @CRLF & _
                                "err.scriptline is: "     & @TAB & $oErrorHandler.scriptline     & @CRLF & _
                                "err.source is: "         & @TAB & $oErrorHandler.source         & @CRLF & _
                                "err.helpfile is: "       & @TAB & $oErrorHandler.helpfile       & @CRLF & _
                                "err.helpcontext is: "    & @TAB & $oErrorHandler.helpcontext & @CRLF _
                            )
EndFunc

 

Br,
UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 2 years later...

2UEZ: script is not working. I'm getting error message:

==> Variable must be of type "Object".:
$colItems = $objWMIService.ExecQuery("SELECT DNSHostName FROM Win32_ComputerSystem", "WQL", 0x30)
$colItems = $objWMIService^ ERROR

What's wrong?

I added an error handling to the code. Post the result from the console.

Did you run it with "127.0.0.1" or with a different host?

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks for quick respond. I ran it with 127.0.0.1. I've got error message:

A COM Error has occured!
err.description is:
err.windescription:
err.number is: 80041017
err.lastdllerror is: 0
err.scriptline is: 11
err.source is:
err.helpfile is:
err.helpcontext is: 7602293

Then I added #RequireAdmin to the script. There was no error message this time but I didn't get any MsgBox (with computer name)

Edited by minimen456
Link to comment
Share on other sites

You are using WinXP and DNSHostName method is not availabe for XP. I changed the code above again. Please try again.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...