Jump to content

Computer or no ?


Recommended Posts

hey,

I am testing a new script at this moment, and i got some problem cause something take too much time.

Here part of my code :

local $timerping = TimerInit()
  $ping = Ping($strComputer & $for,50)
  ConsoleWrite($strComputer & $for & " ping en : " & TimerDiff($timerping) & @crlf)
  if $ping > 0 Then
   local $timerexist = TimerInit()
   If FileExists("\\" & $strComputer & $for & "\c$\") = 1 Then
    ConsoleWrite($strComputer & $for & " existe en : " & TimerDiff($timerexist) & @crlf)

I want to know if at a certain IP adress, its a computer or no ? (only windows)

So, at i'm testing if \\IP.IP.IP.IP\c$ exist, but sometime, it take too much time (timout of function), and if i try to find on if a c$ exist on something which is not a computer, its like 20 s ...

So i'd like to know if there is any way, pretty fast, to know if the IP adress is a computer one or something else ? (any way is ok .)

Jérôme

Link to comment
Share on other sites

For the time Win OSes needs to access a share see

If you're on a domain, I bet things would be easier, but...

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Try this, after your ping returns a valid return, check to see if it's a computer by seeing if there's a C$ share on it. It might have to be run by someone with Administrative rights to the computer you're checking, not sure on that.

$strIPAddr = @IPAddress1
If Ping($strIPAddr) Then
    $objFSO = ObjCreate("scripting.filesystemobject")
    If $objFSO.folderexists("" & $strIPAddr & "c$") Then
        MsgBox(64, "", "It's a computer")
    EndIf
EndIf

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hey,

Just tested, still long time : 26639.588538527 from my timer.

Its a return if i try to find if there is c$ on the ipaddress, which is finally a router.

Just need to know (by any way) is its a computer or no, cause i'd like to run it on the all network (like 192.168.120.10 to 192.168.120.250)

^^

Edited by JeromeB
Link to comment
Share on other sites

There doesn't seem to be any quick fix to the problem of checking if a path exists when doing this. In reading the thread that jchd linked they tried different approaches and none seems to speed up the process a whole lot. But 26 seconds seems a bit excessive.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I mean, if there is an other way to just know if its a computer at a certain ip adress, i take it :oops:

I was testing if a special folder because it was the only i had. But if there is an other way ^^

Wondering on a IsComputer() function ^^

Link to comment
Share on other sites

See if this is any faster, it doesn't check for a share, it checks to see if there is a computer name stored in the registry. I haven't tested it on any computer but my own so I don't know how long it will take to run.

$strIPAddr = @IPAddress1 ; Change to a real IP address, this is YOUR IP addres
If Ping($strIPAddr) Then
;~  $objFSO = ObjCreate("scripting.filesystemobject")
;~  If $objFSO.folderexists("" & $strIPAddr & "c$") Then
;~      MsgBox(64, "", "It's a computer")
;~  EndIf
    $CompName = subGetHostName($strIPAddr)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CompName = ' & $CompName & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

EndIf
Func subGetHostName($IPAddress)
    Local $HKEY_LOCAL_MACHINE = 0x80000002, $strValue
    $objReg = ObjGet("winmgmts:" & $IPAddress & "rootdefault:StdRegProv")
;~  'Get the remote computer name from the registry
    Local $strKeyPath = "SYSTEMCurrentControlSetControlComputerNameActiveComputerName"
    Local $ValueName = "ComputerName"
    $objReg.GetStringValue($HKEY_LOCAL_MACHINE, $strKeyPath, $ValueName, $strValue)
    Return $strValue
EndFunc   ;==>subGetHostName

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

hey,

Nop fail again, aparently cant get object if its not a computer, i get

==> Variable must be of type "Object".:

$objReg.GetStringValue($HKEY_LOCAL_MACHINE, $strKeyPath, $ValueName, $strValue)

$objReg^ ERROR

Anyway, error happen after 15 sec or so ...

^^

Edited by JeromeB
Link to comment
Share on other sites

  • Moderators

This may not be helpful if your domain is huge, but I once worked with a customer that was having DHCP and DNS issues; they would ping an asset by name and get an IP back, but if they pinged by IP with the -a, the address would actually resolve to a different asset. I ended up using the script below to give me an idea of the true asset. In the full script, I read the assets in from a file, but you get the idea. There were only about 500 machines on the domain, but it went pretty quickly. Might be a useful starting point for another way to accomplish what you want.

#include <Constants.au3>

Local $assets[5]
$assets[0] = "110118-IS"
$assets[1] = "109504-IS"
$assets[2] = "109448-IS"
$assets[3] = "103261-IS"
$assets[4] = "105554-CNA"

$net = Run(@ComSpec & " /c ping -a 10.218.128.53", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($net)
    If @error Then ExitLoop
  For $element in $assets
   If StringInStr($line, $element) Then
    MsgBox(0, "Asset is:", $element)
   EndIf
  Next
Wend

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Here's the same script with an error handler for the Object errors so that the if it encounters a problem with the object it won't crash the script. It ran on my computer in about 5 seconds when I tried it on a printer instead of a computer.

$strIPAddr = @IPAddress1 ; Change to a real IP address, this is YOUR IP addres
If Ping($strIPAddr) Then
    $Timer = TimerInit()
    $CompName = subGetHostName($strIPAddr)
    ConsoleWrite("Run time = " & TimerDiff($Timer) & @CRLF)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CompName = ' & $CompName & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
EndIf
Func subGetHostName($IPAddress)
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    Local $HKEY_LOCAL_MACHINE = 0x80000002, $strValue
    $objReg = ObjGet("winmgmts:" & $IPAddress & "rootdefault:StdRegProv")
;~  'Get the remote computer name from the registry
    Local $strKeyPath = "SYSTEMCurrentControlSetControlComputerNameActiveComputerName"
    Local $ValueName = "ComputerName"
    $objReg.GetStringValue($HKEY_LOCAL_MACHINE, $strKeyPath, $ValueName, $strValue)
    Return $strValue
EndFunc   ;==>subGetHostName
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _
            "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            "err.description is: " & @TAB & $oError.description & @CRLF & _
            "err.source is: " & @TAB & $oError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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