weclome to ic0de.ws Check here


Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing webchecker in python
#1
I recently wrote a simple website checker to find server is online or offline.

~ Starting of python script ~

Code:
#!/usr/bin/python

~ Importing modules in python script ~

Code:
import httplib, sys

~ Basic information of httplib module ~

Httplib is HTTP protocol client which uses HTTP/HTTPS to connect to HOST

~  Declaring arguments in our script ~

Code:
if len(sys.argv) < 3:
  sys.exit ( sys.argv[0] + " <websitename> <port>\n")

website = sys.argv[1]
port = sys.argv[2]

if len(sys.argv) < 3: requires  :- basic error checking to check there are at least three elements

sys.exit ( sys.argv[0] + " <websitename> <port>\n") :-  if no arguments is passed sys.exit closes the program
displaying this output
[Image: ea40c1bc04b3e31337587e4563acd51b.png]

website = sys.argv[1]  our arguments
port = sys.argv[2] 
~ Writing httplib objects ~

Code:
client = httplib.HTTPConnection(website,port)
client.request("GET","/")
bringresp = client.getresponse()
client.close()

client = httplib.HTTPConnection(website,port) connects to website and specified port

client.request("GET","/") HTTP method

bringresp = client.getresponse() gets response code for example 504 http code

client.close() closes the connection with website

Code:
if bringresp.status == 200:
  print website + " : website is online"
  sys.exit()

this code blocks checks response if it is 200 then website is online

sys.exit() closes connection

Code:
print website + " website is offline (" + str(bringresp.status) + " , " + bringresp.reason + ")"

if website is offline it shows stats & status reason

~ Final python script ~

Code:
#!/usr/bin/python

import httplib, sys

if len(sys.argv) < 3:
  sys.exit ( sys.argv[0] + " <websitename> <port>\n")

website = sys.argv[1]
port = sys.argv[2]

client = httplib.HTTPConnection(website,port)
client.request("GET","/")
bringresp = client.getresponse()
client.close()

if bringresp.status == 200:
  print website + " : website is online"
  sys.exit()

print website + " website is offline (" + str(bringresp.status) + " , " + bringresp.reason + ")"

~ Preview of python script ~

[Image: 485d5e83b030bd4e3219912aeefc2754.gif]

~ TODO ~
  • parsing txt file with links to find ALIVE OR DEAD
  • implementing screenshot function
  • parsing urls
[Image: BezlSXT.gif]
[-] The following 1 user Likes 0xadmin's post:
  • Xyt0
#2
Great Job! Could prove useful in the near future!

You should make it a Download, the Code containing Rights to you (Creative Commons). This will easily prevent people from stealing your Code and claiming it as their own
#3
(06-01-2020, 04:20 PM)Derek Owumi Wrote: Great Job! Could prove useful in the near future!

You should make it a Download, the Code containing Rights to you (Creative Commons). This will easily prevent people from stealing your Code and claiming it as their own
i don't mind my code being used it is  open-source code anyone can use it.
Aiming to help more users to learn coding & i'm open source lover.
[Image: BezlSXT.gif]


Forum Jump:


Users browsing this thread: 1 Guest(s)