usr bin python TODO IF REBOOTED THEN STOP EVERY 15 MINUTES SEND HTTP R

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
#/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)