Uzun zaman önce yazdığım python kodu
__author__ = 'OSA'
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import time
import telnetlib
import requests
class telnetmi:
def __init__(self):
self.sonuc=""
def aypi(self):
try:
my_ip = requests.get('http://httpbin.org/ip')
sonuc= my_ip.content
except requests.RequestException as e:
#print e
time.sleep(2)
my_ip = requests.get('hhttp://httpbin.org/ip')
sonuc = my_ip.content
print sonuc
return sonuc
def telnetac(self):
HOST = "192.168.2.1" #buraya ipnizi yazin ornek 192.168.1.1 gibi
PORT=22
TIMEOUT=10
user = 'kullaniciadi'
password = 'sifre'
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "n")
if password:
tn.read_until("Password: ")
tn.write(password + "n")
tn.write("kill `cat /var/run/ppp*.pid`m n")
tn.write("ifconfig ppp0n")
tn.write("exitn")
# print tn.read_all()
return tn.read_all()
def sistem(self):
kamil = self.telnetac()
# print kamil
time.sleep(5)
if len(kamil) != 0:
ii= self.aypi()
if ii:
self.sonuc =True
else:
self.sonuc =False
return self.sonuc
a = telnetmi()
print a.sistem()