Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Script to ping a host and if host replies script should exit.

Reply
Thread Tools Display Modes

Script to ping a host and if host replies script should exit.

 
 
Spin
Guest
Posts: n/a

 
      07-27-2008
Gurus,

I am trying to write a script which will ping a host, and if the remote host
replies, the script will exit. Any thoughts? This could be either batch or
VBS.

--
Spin

 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      07-27-2008

"Spin" <> wrote in message
news:...
> Gurus,
>
> I am trying to write a script which will ping a host, and if the remote
> host replies, the script will exit. Any thoughts? This could be either
> batch or VBS.
>
> --
> Spin


Try this batch file:
@echo off
ping SomeHost | find /i "bytes=" && goto :eof


 
Reply With Quote
 
J Ford
Guest
Posts: n/a

 
      07-28-2008
@echo off
ping -n 1 <MachineName>
if %errorlevel% equ 0 goto :eof

"Spin" wrote:

> Gurus,
>
> I am trying to write a script which will ping a host, and if the remote host
> replies, the script will exit. Any thoughts? This could be either batch or
> VBS.
>
> --
> Spin
>
>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      07-28-2008
???

"J Ford" <> wrote in message
news:5053BE14-5F5F-474B-8841-...
> @echo off
> ping -n 1 <MachineName>
> if %errorlevel% equ 0 goto :eof
>
> "Spin" wrote:
>
>> Gurus,
>>
>> I am trying to write a script which will ping a host, and if the remote
>> host
>> replies, the script will exit. Any thoughts? This could be either batch
>> or
>> VBS.
>>
>> --
>> Spin
>>
>>



 
Reply With Quote
 
J Ford
Guest
Posts: n/a

 
      07-28-2008
ping it once, if its successful goto eof

"Pegasus (MVP)" wrote:

> ???
>
> "J Ford" <> wrote in message
> news:5053BE14-5F5F-474B-8841-...
> > @echo off
> > ping -n 1 <MachineName>
> > if %errorlevel% equ 0 goto :eof
> >
> > "Spin" wrote:
> >
> >> Gurus,
> >>
> >> I am trying to write a script which will ping a host, and if the remote
> >> host
> >> replies, the script will exit. Any thoughts? This could be either batch
> >> or
> >> VBS.
> >>
> >> --
> >> Spin
> >>
> >>

>
>
>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      07-28-2008

"J Ford" <> wrote in message
news:8B6869B0-348B-406F-9AAE-...
> ping it once, if its successful goto eof
>


Yes, I know this, seeing that your reply is a long-hand
copy of my own suggestion.


 
Reply With Quote
 
J Ford
Guest
Posts: n/a

 
      07-29-2008
Same posting level... didn't look at yours before I typed mine.

On a side note, I do enjoy your posts because they are more batch specific.

"Pegasus (MVP)" wrote:

>
> "J Ford" <> wrote in message
> news:8B6869B0-348B-406F-9AAE-...
> > ping it once, if its successful goto eof
> >

>
> Yes, I know this, seeing that your reply is a long-hand
> copy of my own suggestion.
>
>
>

 
Reply With Quote
 
Spin
Guest
Posts: n/a

 
      07-31-2008
ping SomeHost | find /i "bytes=" && goto :eof

doesn't work too well. If the 'SomeHost' is un-reachable, I need the script
to proceed to the next line and execute a certain command. If 'SomeHost' is
successfully reachable, only then do I need it to go to :eof. Currently,
just goes to :eof regardless of whether or not 'SomeHost' is reachable.


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      07-31-2008

"Spin" <> wrote in message
news:...
> ping SomeHost | find /i "bytes=" && goto :eof
>
> doesn't work too well. If the 'SomeHost' is un-reachable, I need the
> script to proceed to the next line and execute a certain command. If
> 'SomeHost' is successfully reachable, only then do I need it to go to
> :eof. Currently, just goes to :eof regardless of whether or not
> 'SomeHost' is reachable.


The batch file
@echo off
ping SomeHost | find /i "bytes=" && goto :eof
echo Not found!

will generate the console message "Not found" when
SomeHost is not reachable. I think you have a typing
error in your own command.


 
Reply With Quote
 
Andrew Mishechkin
Guest
Posts: n/a

 
      08-13-2008
Use Win32_PingStatus WMI class

//JScript
var objLocalWMI = GetObject("Winmgmts:");
var enumPingStatus = new Enumerator(objLocalWMI.ExecQuery("Select StatusCode
from Win32_PingStatus Where Address='192.168.1.1'"));
if(enumPingStatus.item().StatusCode == 0)
{
WScript.Echo("It's allright");
WScript.Quit();
}
else
{
WScript.Echo("Host is unreachable");
....
//to do something....
....
}

'VBScript
Set objLocalWMI = GetObject("Winmgmts:")
Set colItems = objLocalWMI.ExecQuery("Select StatusCode from
Win32_PingStatus Where Address='192.168.1.1'",,48)
For Each objItem In colItems
If objItem.StatusCode = 0 Then
WScript.Echo "It's allright"
WScript.Quit
Else
WScript.Echo "Host is unreachable"
...
'to do something
..
End If
Next


"Spin" <> сообщил/сообщила в новостях следующее:
news:...
> Gurus,
>
> I am trying to write a script which will ping a host, and if the remote
> host replies, the script will exit. Any thoughts? This could be either
> batch or VBS.
>
> --
> Spin


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Script Host has no script engine for ".js" files Stephan G. Windows Vista General Discussion 9 04-24-2008 08:04 PM
Windows Script Host for x64 Irbflying Windows 64 Bit 5 10-31-2006 09:41 PM
Script host error Ricky Server Networking 1 04-13-2006 02:52 AM
ASP.NET and Windows Host Script Salim Scripting 1 01-10-2004 04:38 PM
script host roben Scripting 1 11-29-2003 06:04 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59