Sign in to follow this  
Followers 0
dkwokgs

How To Detect Lan And Offline From Script?

5 posts in this topic

Hi there,

Is there a way write a script to detect LAN connection to a server eg. 192.168.100.100 upon login loging on to the system and if server exist run the certain program,if not run another program?

Regards

Daniel

Share this post


Link to post
Share on other sites



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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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 ...

.

.

.

-----

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thanks a lot for the info.

Cheers

Daniel

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0