Jump to content

How To Detect Lan And Offline From Script?


dkwokgs
 Share

Recommended Posts

  • Developers

this is a v3 script that works for WinXP, for other WinOS you migth need to check the ping parameters:

; Run ping with count=1 and timeout = 1 second
$rc = RunWait(@comspec &  ' /c ping 192.168.100.100 -n 1 -w 1000','',@SW_HIDE)
If $rc = 0 Then
  ; host exists
Else
  ; host doesn't exists
EndIf

in ver2 something like this : (not tested)

Run, %COMSPEC% /c ping 192.168.100.100 -n 1 -w 1000 ,,hide
IfEqual, ERRORLEVEL, 0, Goto, HostExists
; host doesn't exist
.....
exit
;
HostExists:
; host exists
.....
exit

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ping the server, redirect response to a file, check the file content.

If server has replied, use net use to connect to the server

If he's not active, do something different (eg. wait before you check'm again) ...

-----

Ping:

RunWait, %COMSPEC% /C PING www.hiddensoft.com > %TEMP%\PingResponse.txt

SetEnv, ln, 3

SetEnv, to, 0

Check:

FileReadLine, PingResp, %TEMP%\PingResponse.txt, %ln%

IfInString, PingResp, Reply from, EnvAdd, to, 1

EnvAdd, ln, 1

IfLessOrEqual, ln, 7, Goto, Check

ToBeOrNotToBe:

IfEqual, to, 4, Goto, Connect

ServerDown:

Repeat, 60

Sleep, 1000

EndRepeat

Goto, Ping

Connect:

Run, %COMSPEC% /C net use ...

.

.

.

-----

Link to comment
Share on other sites

My script for knowing if a computer is on or off.

IfLess,0,1,exit,255

RunWait,%comspec% /c ping -n 1 -w 50 %1%>%temp%\ison.tmp,,hide

FileReadLine,text, %temp%\ison.tmp, 7
RunWait,%comspec% /c del %temp%\ison.tmp,,hide

IfNotInString,text,Ricevuti = 1,goto,off

;"Ricevuti" should be changed with the word that appear in your language.

;on
exit,0

off:
exit,1
Edited by ezzetabi
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...