Esempio n. 1
0
 def SendNow(self, msg):
     if self.sendError: return
     if self.telnet:
         msg = Telnet.filter_out(msg)
     if not msg: return
     try:
         self.conn.send(msg + self.nl)
     except socket.error:
         self.sendError = True
         self.Remove()
Esempio n. 2
0
	def SendNow(self, msg):
		if self.sendError: return
		if self.telnet:
			msg = Telnet.filter_out(msg)
		if not msg: return
		try:
			self.conn.send(msg+self.nl)
		except socket.error:
			self.sendError = True
			self.Remove()
Esempio n. 3
0
def start_session(device, username, password, enable_username, enable_password,
                  via):
    session = None
    if via == 'telnet':
        session = Telnet.Telnet(device, username, password, enable_username,
                                enable_password)
    if via == 'ssh':
        session = Secure_Shell.Secure_Shell(device, username, password,
                                            enable_username, enable_password)
    return session
Esempio n. 4
0
	def Send(self, msg):
		if self.telnet:
			msg = Telnet.filter_out(self,msg)
		
		if not msg: return

		if self.handler.thread == thread.get_ident():
			msg = self.msg_id + msg
			
		self.sendbuffer.append(msg+self.nl)
		self.handler.poller.setoutput(self.conn, True)
Esempio n. 5
0
    def Send(self, msg):
        if self.telnet:
            msg = Telnet.filter_out(self, msg)

        if not msg: return

        if self.handler.thread == thread.get_ident():
            msg = self.msg_id + msg

        self.sendbuffer.append(msg + self.nl)
        self.handler.poller.setoutput(self.conn, True)
Esempio n. 6
0
 def Handle(self, data):
     if self.bot and not (self.access in self.floodlimit
                          and 'disabled' in self.floodlimit[self.access]):
         limit = self.floodlimit['bot']
     elif self.access in self.floodlimit:
         limit = self.floodlimit[self.access]
     else:
         limit = self.floodlimit['user']
     if not 'disabled' in limit:
         msglength = limit['msglength']
         bytespersecond = limit['bytespersecond']
         seconds = limit['seconds']
         now = int(time.time())
         self.lastdata = now
         if now in self.msglengthhistory:
             self.msglengthhistory[now] += len(data)
         else:
             self.msglengthhistory[now] = len(data)
         total = 0
         for iter in dict(self.msglengthhistory):
             if iter < now - (seconds - 1):
                 del self.msglengthhistory[iter]
             else:
                 total += self.msglengthhistory[iter]
         if total > (bytespersecond * seconds):
             self.SendNow(
                 'SERVERMSG No flooding (over %s per second for %s seconds)'
                 % (bytespersecond, seconds))
             self.Remove('Kicked for flooding')
             return
     self.data += data
     if self.data.count('\n') > 0:
         data = self.data.split('\n')
         (datas, self.data) = (data[:len(data) - 1],
                               data[len(data) - 1:][0])
         for data in datas:
             if data.endswith(
                     '\r'
             ) and self.telnet:  # causes fail on TASClient, so only enable on telnet
                 self.nl = '\r\n'
             command = data.rstrip('\r').lstrip(
                 ' ')  # strips leading spaces and trailing carriage return
             if not 'disabled' in limit and len(command) > msglength:
                 self.Send(
                     'SERVERMSG Max length exceeded (%s): no message for you.'
                     % msglength)
             else:
                 if self.telnet:
                     command = Telnet.filter_in(self, command)
                 if type(command) == str:
                     command = [command]
                 for cmd in command:
                     self._protocol._handle(self, cmd)
Esempio n. 7
0
	def Handle(self, data):
		if self.bot and not (self.access in self.floodlimit and 'disabled' in self.floodlimit[self.access]): limit = self.floodlimit['bot']
		elif self.access in self.floodlimit: limit = self.floodlimit[self.access]
		else: limit = self.floodlimit['user']
		if not 'disabled' in limit:
			msglength = limit['msglength']
			bytespersecond = limit['bytespersecond']
			seconds = limit['seconds']
			now = int(time.time())
			self.lastdata = now
			if now in self.msglengthhistory:
				self.msglengthhistory[now] += len(data)
			else:
				self.msglengthhistory[now] = len(data)
			total = 0
			for iter in dict(self.msglengthhistory):
				if iter < now - (seconds-1):
					del self.msglengthhistory[iter]
				else:
					total += self.msglengthhistory[iter]
			if total > (bytespersecond * seconds):
				self.SendNow('SERVERMSG No flooding (over %s per second for %s seconds)'%(bytespersecond, seconds))
				self.Remove('Kicked for flooding')
				return
		self.data += data
		if self.data.count('\n') > 0:
			data = self.data.split('\n')
			(datas, self.data) = (data[:len(data)-1], data[len(data)-1:][0])
			for data in datas:
				if data.endswith('\r') and self.telnet: # causes fail on TASClient, so only enable on telnet
					self.nl = '\r\n'
				command = data.rstrip('\r').lstrip(' ') # strips leading spaces and trailing carriage return
				if not 'disabled' in limit and len(command) > msglength:
					self.Send('SERVERMSG Max length exceeded (%s): no message for you.'%msglength)
				else:
					if self.telnet:
						command = Telnet.filter_in(self,command)
					if type(command) == str:
						command = [command]
					for cmd in command:
						self._protocol._handle(self,cmd)
#!/usr/bin/python3.7

import Telnet from telnetlib

target="10.171.1.129"

telnetconn = Telnet(target)

Esempio n. 9
0
import getdataV2
import Telnet
IPadd ='192.168.1.5'
G1NAME = getdataV2.Get_PortInfo_Range_IF0('H5', IPadd, 10101, 10124)

test = Telnet.telnet_super(IPadd, 'H5-prog', 'cisco')
#test.reload()
test.config_interface_range_Vlan(G1NAME.name, '666')

'''HOST = "192.168.1.5"
#user = raw_input("Enter your remote account: ")
password = '******'

child = pexpect.spawn('telnet '+HOST)
child.expect('Password: '******'>')
child.sendline('enable')
child.sendline(password)
child.sendline ('conf t')
for l in G1NAME.name:
    child.sendline('interface '+ l)
    child.sendline('sw mode acc')
    child.sendline('sw acc vl 666')
'''