Jump to content

Pinging a website

pxnguinPr3

Hi, I was trying to figure out a way to ping my website to check its running, and if its not output a gpio signal from a raspberry pi to light up a LED (I can do the gpio signal part)
 

But couldnt for the life of my figure out any way to use python to ping a website.

 

Thanks for any help,

 

Pxnguin

Hi.

 

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, pxnguinPr3 said:

Hi, I was trying to figure out a way to ping my website to check its running, and if its not output a gpio signal from a raspberry pi to light up a LED (I can do the gpio signal part)
 

But couldnt for the life of my figure out any way to use python to ping a website.

 

Thanks for any help,

 

Pxnguin

You don't ping a website. You ping a server. ICMP packets are sent to a network device, not to an application (web server).

You can send an HTTP request to the website and check if that gives what it has to (check the status code, check the body).

 

For that I recommend Python requests module.

HAL9000: AMD Ryzen 9 3900x | Noctua NH-D15 chromax.black | 32 GB Corsair Vengeance LPX DDR4 3200 MHz | Asus X570 Prime Pro | ASUS TUF 3080 Ti | 1 TB Samsung 970 Evo Plus + 1 TB Crucial MX500 + 6 TB WD RED | Corsair HX1000 | be quiet Pure Base 500DX | LG 34UM95 34" 3440x1440

Hydrogen server: Intel i3-10100 | Cryorig M9i | 64 GB Crucial Ballistix 3200MHz DDR4 | Gigabyte B560M-DS3H | 33 TB of storage | Fractal Design Define R5 | unRAID 6.9.2

Carbon server: Fujitsu PRIMERGY RX100 S7p | Xeon E3-1230 v2 | 16 GB DDR3 ECC | 60 GB Corsair SSD & 250 GB Samsung 850 Pro | Intel i340-T4 | ESXi 6.5.1

Big Mac cluster: 2x Raspberry Pi 2 Model B | 1x Raspberry Pi 3 Model B | 2x Raspberry Pi 3 Model B+

Link to comment
Share on other sites

Link to post
Share on other sites

A super basic and simple way would be to use https://docs.python.org/2/library/robotparser.html

Put a robots.txt on your website and use those functions to check if it can be retrieved.

 

Pinging a ip doesn't mean a website is live, this ensures the http server is also on and can serve files to you and since robots.txt is only a few bytes, it can be easy on everything.

 

Another option is to use the socket functions : https://docs.python.org/2/library/socket.html#example

See first example, the client part (the bit with # Echo client program at the start) ... change it so you just connect and read some data instead of sending anything. If your web site has a ftp server, connect to ip and port 21  and as soon as you're connected the server should send a text with something like type your username and password etc so you'll know it's a ftp server)

Link to comment
Share on other sites

Link to post
Share on other sites

21 minutes ago, James Evens said:

Do you need a Pi? The ESP8266 is much cheaper. One way would be to use the ping library for the esp8266.

If you want to use a pi it comes with a full linux which has the ping command is build in. Just write a short script.

Ah, alright. I already have a pi, i just need a way to get the ping command to communicate with python as im using a python library called Blinkt! as status LEDS.

Hi.

 

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, pxnguinPr3 said:

Ah, alright. I already have a pi, i just need a way to get the ping command to communicate with python as im using a python library called Blinkt! as status LEDS.

As said just throw a file in the root and use requests library to hit the file and see if it's there.

 

Also just because the site is live doesn't mean it's functioning

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×