|
2 Nov 2003, 12:56
|
#1
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
PHP ping
Ok, head hurts
Has anyone any idea how to ping an IP address from a PHP script? I seem to be looking at raw sockets and I don't like that much at all
P.S. Any answers involving exec() or similar will result in me screaming at you incoherently.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
2 Nov 2003, 13:37
|
#2
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Re: PHP ping
I tried playing with raw sockets and discovered that crappy webhost doesn't allow them
Bleugh.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
2 Nov 2003, 13:40
|
#3
|
Banned
Join Date: Dec 2000
Location: autogenic misery
Posts: 872
|
Re: PHP ping
|
|
|
2 Nov 2003, 13:45
|
#4
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Re: PHP ping
Google has many many links to scripts using exec() or similar and parsing the resulting output string.
I wanted to do it natively and the only link I found used raw sockets which my webhost doesn't allow and I don't know of any other way of doing it
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
2 Nov 2003, 13:54
|
#5
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: PHP ping
Try connecting to the host as if it were a webpage or similar using the standard file IO functions and timing how long it takes, it might be a bodged effort if there's no other way. Then deduct some small percentage to take into account any target system overhead that may have existed.
Can't think of another way without using sockets.
__________________
You're now playing ketchup
|
|
|
2 Nov 2003, 14:44
|
#6
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Re: PHP ping
Quote:
Originally Posted by pablissimo
Try connecting to the host as if it were a webpage or similar using the standard file IO functions
|
That's what I'm doing as a bodge job. I'm not really bothered about the ping time, I just want to know it's replying.
However, I may alter this so it opens a telnet connection to the remote router as a comms check. That would work as well as a ping
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
3 Nov 2003, 18:31
|
#7
|
Registered User
Join Date: Apr 2002
Location: Leeds, but looking for a way to escape
Posts: 128
|
Re: PHP ping
__________________
SELECT everything FROM everywhere WHERE something = something_else;
> 42
|
|
|
3 Nov 2003, 18:40
|
#8
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: PHP ping
Quote:
Originally Posted by BuddhistPunk
|
Quote:
Originally Posted by that website
Note that access to raw sockets requires root access, so this script also requires root access - rendering it more or less useles for web applications
|
Quote:
Originally Posted by Gayle29uk
and the only link I found used raw sockets which my webhost doesn't allow
|
__________________
You're now playing ketchup
|
|
|
3 Nov 2003, 18:53
|
#9
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Re: PHP ping
Quote:
Originally Posted by pablissimo
<observant>
|
Yup, that's the one
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
3 Nov 2003, 21:19
|
#10
|
Banned
Join Date: Dec 2000
Location: autogenic misery
Posts: 872
|
Re: PHP ping
|
|
|
4 Nov 2003, 01:31
|
#11
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: PHP ping
That... wasn't useful at all.
Of the ones I found on Google, most used some variation of exec, some used raw sockets, and one
Code:
<?php
function ping($host)
{
$ip = gethostbyname($host);
$ping = `ping -c 1 -q $ip`;
$res = '1 packets transmitted, 1 packets recieved';
if(strpos($ping, $res))
return true;
else
return false;
}
?>
Doesn't actually appear to do...anything of value
ps Google is inf's friend
__________________
You're now playing ketchup
Last edited by pablissimo; 4 Nov 2003 at 01:41.
|
|
|
4 Nov 2003, 13:25
|
#12
|
Throwing Shapes
Join Date: Apr 2000
Posts: 797
|
Re: PHP ping
dont these scripts rely on two things?
1) What type of Web Server it is (IIS/Apache etc.. Linux/Windows or whatever) and
2) Whether or not the host actually allows ICMP packets to be sent from the webserver.
__________________
Time is an Illusion, Lunchtime doubly so.
|
|
|
4 Nov 2003, 13:40
|
#13
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: PHP ping
...yes
__________________
You're now playing ketchup
|
|
|
4 Nov 2003, 18:07
|
#14
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Re: PHP ping
Quote:
Originally Posted by pablissimo
Of the ones I found on Google, most used some variation of exec, some used raw sockets, and one
Code:
<?php
function ping($host)
{
$ip = gethostbyname($host);
$ping = `ping -c 1 -q $ip`;
$res = '1 packets transmitted, 1 packets recieved';
if(strpos($ping, $res))
return true;
else
return false;
}
?>
Doesn't actually appear to do...anything of value
|
Enclosing a command in backticks (``) executes it as a shell command and returns the output
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
4 Nov 2003, 18:12
|
#15
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: PHP ping
Quote:
Originally Posted by Gayle29uk
Enclosing a command in backticks (``) executes it as a shell command and returns the output
|
You learn something every day.
So how would you make a string that corresponds to a command but you don't want evaluated? Escape 'everything'?
__________________
You're now playing ketchup
|
|
|
5 Nov 2003, 20:36
|
#16
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Re: PHP ping
What are you looking for? A way to send raw packets even though you're explicitly not allowed to? There is a reason /bin/ping has to be SUID on a usual unixy setup, even if I personally don't think the reasons are very good. What you are asking is simply not allowed by the security model.
(You could use a seperate ping-daemon thing if the original post is a trick question.)
__________________
#linux
|
|
|
5 Nov 2003, 21:13
|
#17
|
Gubbish
Join Date: Sep 2000
Location: #FoW
Posts: 2,323
|
Re: PHP ping
Quote:
Originally Posted by pablissimo
You learn something every day.
So how would you make a string that corresponds to a command but you don't want evaluated? Escape 'everything'?
|
Backticks (`) are different from single quotes (') and double quotes (")
__________________
Gubble gubble gubble gubble
|
|
|
5 Nov 2003, 21:20
|
#18
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: PHP ping
Ohhh backticks
I was reading them as single quotes =((
__________________
You're now playing ketchup
|
|
|
5 Nov 2003, 21:33
|
#19
|
Bitch
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
|
Re: PHP ping
Quote:
Originally Posted by queball
What are you looking for? A way to send raw packets even though you're explicitly not allowed to? There is a reason /bin/ping has to be SUID on a usual unixy setup, even if I personally don't think the reasons are very good. What you are asking is simply not allowed by the security model.
(You could use a seperate ping-daemon thing if the original post is a trick question.)
|
I wanted to ping a remote server to see if it was up or not. Instead I've implemented it in a little more detail and it now uses fsockopen() to open a socket to host ort which lets me monitor specific services instead of just whether as host is up or not.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
|
|
|
|
All times are GMT +1. The time now is 21:45.
| |