I am trying to build a little script that helps me ping hosts by using a python script via browser.
I am stuck and I need some advice. I am new to python.
Bellow is the code I have written so far...
# !/usr/bin/python
import os.path
import urlparse
print('Content-type: text/html\r\n\r')
url = os.environ['HTTP_HOST']
uri = os.environ['REQUEST_URI']
link = url + uri
print("<br>\n{}\n<br>".format(link))
parsed = urlparse.urlparse(link)
theparameter = urlparse.parse_qs(parsed.query)['name']
thehost = (theparameter)[0]
print("===============\n{}\n===============".format(thehost))
print("<br>")
os.system("ping -c 4 {}".format(thehost))
# print("<br>")
In the apache error logs I have the following error:
malformed header from script 'test.py': Bad header: PING <theIPaddress> (<theIPaddress>)
Thank you!
Later edit: I found a solution to my question.
check = ("ping -c 4 {}".format(thehost))
result = os.popen(check).read()
print "<pre>"
print result
print "</pre>"