connect or disconnect

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

connect or disconnect

#1 Post by Mohammad_Dos » 11 Jul 2011 00:57

I want to write a batch file that tell me i am connected to the internet or disconnected.
by using "ping" and "erorlevel"

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: connect or disconnect

#2 Post by Mohammad_Dos » 11 Jul 2011 04:39

someone answer me!!!

shiva
Posts: 18
Joined: 11 Jul 2011 03:53

Re: connect or disconnect

#3 Post by shiva » 11 Jul 2011 04:56

hai
i am unable to get the server address with batch programming,
but using google site as server i made the batch file,
this will not effect any other server address
the batch file is as follows:

@echo off

set server=www.google.com

ping %server%
if %ERRORLEVEL%==0 (
@echo internet was connected
) else (
@echo internet was notconnected
)
@echo on
pause


this will show the internet connectivity,
if you are intrested change your local subscriber address as server address,
thank you
shiva :D :)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: connect or disconnect

#4 Post by aGerman » 11 Jul 2011 10:15

... or something like that:

Code: Select all

@echo off
ping -n 1 google.com >nul &&(
  echo connected
) || (
  echo disconnected
)
pause


Regards
aGerman

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: connect or disconnect

#5 Post by Cleptography » 11 Jul 2011 17:07

aGerman wrote:... or something like that:

Code: Select all

@echo off
ping -n 1 google.com >nul &&(
  echo connected
) || (
  echo disconnected
)
pause


Regards
aGerman


@aGerman
Could you explain how this script is working, I am fumbling with the concept of ) || (
Thank you.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: connect or disconnect

#6 Post by aGerman » 12 Jul 2011 10:50

command1 && command2
command2 will be executed if command1 was successful (ErrorLevel is 0)

command1 || command2
command2 will be executed if command1 failed (ErrorLevel not 0)

command1 && command2 || command3
command2 will be executed if command1 was successful, else command3 will be executed.

Regards
aGerman

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: connect or disconnect

#7 Post by Cleptography » 12 Jul 2011 11:26

@aGerman
Thank You. 8)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: connect or disconnect

#8 Post by aGerman » 12 Jul 2011 11:36

You're welcome.
I had a c/p failure in my 2nd example ... fixed.

Regards
aGerman

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: connect or disconnect

#9 Post by Mohammad_Dos » 12 Jul 2011 13:16

thank u shiva
thank u aGerman

shiva
Posts: 18
Joined: 11 Jul 2011 03:53

Re: connect or disconnect

#10 Post by shiva » 07 Aug 2011 23:54

you are welcome dude..........., :D :D

Post Reply