#/usr/bin/python
"""
TODO:
1) IF REBOOTED THEN STOP
2) EVERY 15 MINUTES SEND HTTP REQUEST
3) LOGGER
"""
import os, sys
import telnetlib
import subprocess
import time
import socket
import random
HOST = "192.168.1.1"
DEBUG = 0
FREEBSD = 0
def reboot():
n = 0
user = 'Reset'
password = '6473645'
while 10 > n:
tn = telnetlib.Telnet("192.168.1.1")
if DEBUG:
tn.set_debuglevel(9)
time.sleep(2.0)
try:
tn.read_until("Login: ", 5)
tn.write(user+"\r")
tn.read_until("Password: ", 5)
tn.write(password+"\r")
tn.read_until("Login successful", 5)
print "Login successful"
tn.read_until("--> ", 3)
tn.write("help\r")
print tn.read_until("--> ", 5)
tn.write("user logout\r")
except EOFError, socket.error:
print time.strftime("%H:%M:%S "),
print "Telnet failure on Server "
n = n + 1
def logger(q):
file = open("daemon.log","w")
for line in q:
file.write(q)
file.close()
def inet_checker():
# ICMP method
sites = ['www.google.ru','www.rambler.ru',
'www.yahoo.com','www.mail.ru',
'www.ukr.net','www.google.com.ua']
rand = random.randint(0,len(sites))
site = sites[rand]
test = "ping %s -n 30" % site
process = subprocess.Popen(test, shell=True, stdout=subprocess.PIPE)
process.wait()
# 0 - ok, 1 - bad
if process.returncode:
print "fuck"
#reboot()
time.sleep(1000)
else:
print "so ok"
def addon(site):
# DNS method
try:
s = socket.gethostbyname(site)
print s
except socket.gaierror:
print "error"
counter = 0
# Http method
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("www.rambler.ru", 80))
time.sleep(2)
except socket.gaierror:
counter = counter + 1
#reboot()
if FREEBSD:
if os.fork()==0:
os.setsid()
sys.stdout=open("/dev/null", 'w')
sys.stdin=open("/dev/null", 'r')
if os.fork()==0:
while 1:
inet_checker()
time.sleep(20)
sys.exit(0)
else:
while 1:
inet_checker()
time.sleep(20)