/    Sign up×
Community /Pin to ProfileBookmark

Hi,

I wrote a very simple ping script to verify the host is reachable or not.

[CODE]$host = “yahoo.com”;
//$name = gethostbyaddr($ip);

$str = system(“ping -n 1 $host”);
echo ‘<br><br>’;
If (strstr($str, ‘Reply’) == TRUE) {
echo “<font color=’red’><b>$host</b> is REACHABLE</font>” ;
}
Else {
echo “<font color=’red'<b>$host</b> is UNREACHABLE</font>”;
}[/CODE]

What happen is I just want it to echo either $host is REACHABLE or UNREACHABLE. I use $str = system(“ping -n 1 $host”); to store the output result and read from it, but somehow the page keep showing the Ping Result also. Like below:

[QUOTE]

Pinging yahoo.com [216.109.112.135] with 32 bytes of data: Reply from 216.109.112.135: bytes=32 time=82ms TTL=54 Ping statistics for 216.109.112.135: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 82ms, Maximum = 82ms, Average = 82ms

yahoo.com is UNREACHABLE

[/QUOTE]

If there is a way to disable echo for $str = system(“ping -n 1 $host”); ? or filter the ping result out and just echo the REACHABLE and UNREACHABLE condition?

Thanks in advance.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Mar 10.2007 — Use exec() instead...
Copy linkTweet thisAlerts:
@SunnyVuauthorMar 10.2007 — It works now!!!. Thanks again NightShift58. ?
Copy linkTweet thisAlerts:
@NightShift58Mar 10.2007 — You're welcome again!
×

Success!

Help @SunnyVu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...