|
Versions Of This Snippet::
Download a raw-text version of this code by clicking on "Download Version"
Latest Snippet Version: :1.0
#!/usr/bin/python
# written and tested with
# python 2.6.5 on linux
# peter bauer
# peba@inode.at
import os, string, urllib, sys
global dbox_ip
dbox_ip=("192.168.1.2")
command=("ping -c1 ")
param=command + dbox_ip
str=os.popen(param).read() #gets a file object
if "error" in str: #error in ping command
print ("host " + dbox_ip + " not reachable")
print "exiting program\n"
exit ()
else:
print ("host " + dbox_ip + " is reachable")
class DreamMsg:
def __init__(self):
self.message = ""
def send(self,message):
http_message="http://" + dbox_ip + "/cgi-bin/message?" + message
urllib.urlopen(http_message).read()
sender=DreamMsg()
args=sys.argv #get ARGV
if len(args) == 2:
mess=sys.argv[1].replace(" ","+")
sender.send(mess)
else: #read from tty
print "Please enter message below and press Return"
mess = sys.stdin.readline().replace(" ","+").rstrip("\n")
sender.send(mess)
Submit a new versionYou can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..
|
||||||||||||||||||||||||||
