Giter Club home page Giter Club logo

pythonvideos's People

Contributors

davidbombal avatar spidernik84 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pythonvideos's Issues

GNS3 Talks: Python for Network Engineers with GNS3 (Part 5) - Multiple switches, multiple VLANs - ISSUE

Hello David. Any reason why this only configure one switch? I am able to telnet from my SW1 to all the devices and also from my home laptop that run the script. Every time I ran it, it only configure SW4, if I reduce the range, it will take any of the random SW

#!/usr/local/bin/python3.9

import getpass
import sys
import telnetlib

user = input("Enter your telnet user name: ")
password = getpass.getpass()

for n in range (10,14):
HOST = "10.115.0." + str(n)
tn = telnetlib.Telnet(HOST)

tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

tn.write(b"config t\n")

for n in range(2,11):
     tn.write(b"vlan " + str(n).encode('ascii') + b"\n")
     tn.write(b"name Python_VLAN_" + str(n).encode('ascii') + b"\n")

tn.write(b"end\n")
tn.write(b"write\n")
tn.write(b"exit\n")

print(tn.read_all().decode('ascii'))

Netmiko/Paramiko SSH issue

Hi, when we are trying to config_set with list as below,

config_commands = ['int loop 0', 'ip address 1.1.1.1 255.255.255.0']
output = net_connect.send_config_set(config_commands)
print (output)

We get the following error.

root@Ubuntu-2:~# python3 netmiko1.py
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 unassigned YES unset up up
Vlan1 192.168.47.144 YES manual up up
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/paramiko/channel.py", line 699, in recv
out = self.in_buffer.read(nbytes, self.timeout)
File "/usr/local/lib/python3.5/dist-packages/paramiko/buffered_pipe.py", line 164, in read
raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/netmiko/base_connection.py", line 534, in _read_channel_expect
new_data = self.remote_conn.recv(MAX_BUFFER)
File "/usr/local/lib/python3.5/dist-packages/paramiko/channel.py", line 701, in recv
raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "netmiko1.py", line 18, in
output = net_connect.send_config_set(config_commands)
File "/usr/local/lib/python3.5/dist-packages/netmiko/base_connection.py", line 1607, in send_config_set
output = self.config_mode(*cfg_mode_args)
File "/usr/local/lib/python3.5/dist-packages/netmiko/cisco_base_connection.py", line 50, in config_mode
config_command=config_command, pattern=pattern
File "/usr/local/lib/python3.5/dist-packages/netmiko/base_connection.py", line 1514, in config_mode
if not self.check_config_mode():
File "/usr/local/lib/python3.5/dist-packages/netmiko/cisco/cisco_ios.py", line 32, in check_config_mode
check_string=check_string, pattern=pattern
File "/usr/local/lib/python3.5/dist-packages/netmiko/cisco_base_connection.py", line 38, in check_config_mode
check_string=check_string, pattern=pattern
File "/usr/local/lib/python3.5/dist-packages/netmiko/base_connection.py", line 1501, in check_config_mode
output = self.read_until_pattern(pattern=pattern)
File "/usr/local/lib/python3.5/dist-packages/netmiko/base_connection.py", line 609, in read_until_pattern
return self._read_channel_expect(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/netmiko/base_connection.py", line 543, in _read_channel_expect
"Timed-out reading channel, data not available."
netmiko.ssh_exception.NetMikoTimeoutException: Timed-out reading channel, data not available.
root@Ubuntu-2:~#

did not get last host

Hi David,

I used your script but doesn't do telnet all host. Please check my error:

oot@NetworkAutomation-1:~# ./pythonloopscript
Enter your telnet username: username
Password:
Telnet to host36
Telnet to host37
Telnet to host38

here is my script:

#!/usr/bin/env python
import getpass
import sys
import telnetlib

user = raw_input("Enter your telnet username: ")
password = getpass.getpass()

for n in range (36,39):
print ("Telnet to host") + str(n)
HOST = "192.168.13." + str(n)
tn = telnetlib.Telnet(HOST)

tn.read_until("Username: ")
tn.write(user + "\n")

if password:
tn.read_until("Password: ")
tn.write(password + "\n")

tn.write("conf t\n")

for n in range (2,21):
tn.write("no banner exec ^C " + "\n")
tn.write("no banner incoming ^C " + "\n")
tn.write("no banner login ^C " + "\n")
tn.write("no vlan " + str(n) + "\n")

Thanks.

my experience with pythonR1script1.py

I started doing to work with the script just to wet my beak using python API's and realized this script works great for commands being entered into "config T" however it hangs for show commands, does anyone know why? Just curious?

ACL find and add project - Network Scripting

Hi Guys,

Need some help with getting the following script to work:

1 - Script connects to Switches which are a mix of telnet, ssh using tacacs and local accounts for authentication.
2 - Check if any of the following ACL's are on the switch and if so then paste the config for the respective acl found on the switch only. For e.g. switch A has acl 101, 102 and test acl configured, so all 3 acls will need to updated with new network address, then switchB only has acl 102, so only 102 will be updated on switchB.
3 - to do show acl xxx (101, 102, testacl) post updating and copy this to a file with the switch name

Below is the config that needs to be pasted on the switches and it will be the same for all 3 acl's (101,102&testacl):

access-list extended 101
109 permit ip 10.10.0.0 0.0.0.255
exit
access-list resequence 101 10 10
end
show access-list 101
wr mem

========
I have tried the following code but its not working.

import getpass
import sys
import telnetlib
from sys import argv
import csv
import ipaddress
import requests
from netmiko import ConnectHandler




switchdata, device_lists, = argv 

reader = csv.DictReader(open(device_lists, 'rb'))

device_lists = []

for line in reader:
	device_lists.append(line)

username = raw_input("Username: ")
password = getpass.getpass("Password ")
enablepw = getpass.getpass("Enable Password ")

for device in device_lists:
	print "\n\n-------------\nDevice: {0} \n----------\n".format(device['host'])
	try:
		device['device_type'] = 'cisco_ios_ssh'
		device['username'] = username
		device['password'] = password
		device['secret'] = enablepw
		net_connect = ConnectHandler(**device)

	except:
		try:
			device['device_type'] = 'cisco_ios_telnet'
			device['username'] = username
			device['password'] = password
			device['secret'] = enablepw
			net_connect = ConnectHandler(**device)

		except:
	   		print "Unable to connect!"
	    	continue
	net_connect.enable()

print "\n"


output = net_connect.send_command("show access-list 101")

with open('acl_101' + device['host'] + '.txt', 'w' ) as acl101:
	for line in output.splitlines():
		if "101" in line:
			output = net_connect.send_command("enable\n")
			output = net_connect.send_command(password + "\n")
			output = net_connect.send_command("config t\n")
			output = net_connect.send_command("ip access-list extended 101\n")
			output = net_connect.send_command("109 permit ip 10.10.0.0 0.0.0.255 any\n")
			output = net_connect.send_command("exit\n")
			output = net_connect.send_command("access-list resequence 101\n")
			output = net_connect.send_command("end\n")
			output = net_connect.send_command("show access-list 101\n")
			output = net_connect.send_command("show hostname\n")
			print "    " + line



output = net_connect.send_command("show ip access-list 102")

with open('acl_102' + device['host'] + '.txt', 'w') as acl102:
	for line in output.splitlines():
		if "102" in line:
			output = net_connect.send_command("enable\n")
			output = net_connect.send_command(password + "\n")
			output = net_connect.send_command("config t\n")
			output = net_connect.send_command("ip access-list extended 102\n")
			output = net_connect.send_command("109 permit ip 10.10.0.0 0.0.0.255 any\n")
			output = net_connect.send_command("exit\n")
			output = net_connect.send_command("access-list resequence 102\n")
			output = net_connect.send_command("end\n")
			output = net_connect.send_command("show access-list 102\n")
			output = net_connect.send_command("show hostname\n")



output = net_connect.send_command("show ip access-list test")

with open('testacl' + device['host'] + '.txt', 'w') as testacl:
	for line in output.splitlines():
		if "testacl" in line:
			output = net_connect.send_command("enable\n")
			output = net_connect.send_command(password + "\n")
			output = net_connect.send_command("config t\n")
			output = net_connect.send_command("ip access-list extended test\n")
			output = net_connect.send_command("109 permit ip 10.10.0.0 0.0.0.255 any\n")
			output = net_connect.send_command("exit\n")
			output = net_connect.send_command("access-list resequence test\n")
			output = net_connect.send_command("end\n")
			output = net_connect.send_command("show access-list testacl\n")
			output = net_connect.send_command("show hostname\n")
		print "    " + line

Thanks in advance!

switchloopfile.py - Telnet error

I'm getting an error when I try to run your script and can not figure out what's going wrong

$ python pythonR1script5.py

Enter your remote account: david
Password: cisco
Configuring Router 192.168.1.101

Traceback (most recent call last):
  File "pythonR1script5.py", line 13, in <module>
    tn = telnetlib.Telnet(HOST)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/telnetlib.py", line 211, in __init__
    self.open(host, port, timeout)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/telnetlib.py", line 227, in open
    self.sock = socket.create_connection((host, port), timeout)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

The code:

import getpass
import sys
import telnetlib

user = raw_input("Enter your remote account: ")
password = getpass.getpass()

f = open ('myrouters')

for line in f:
    print "Configuring Router " + (line)
    HOST = line
    tn = telnetlib.Telnet(HOST)

    tn.read_until("Username: ")
    tn.write(user + "\n")
    if password:
        tn.read_until("Password: ")
        tn.write(password + "\n")

    tn.write("conf t\n")

    for n in range (0,2):
        tn.write("interface loopback " + str(n) + "\n")
        tn.write("ip address 1.1." + str(n) + ".2 255.255.255.0\n")

    tn.write("end\n")
    tn.write("exit\n")

    print tn.read_all()

Unable to Telnet "Telnet received DONT Echo (1)"

Hi David,

I am unable to establish a connection by using the PythonR1Script1. I am getting an error as mentioned in the title.

The debug is as below:

*Mar 1 00:05:25.199: Telnet130: 1 1 251 1
*Mar 1 00:05:25.199: TCP130: Telnet sent WILL ECHO (1)
*Mar 1 00:05:25.199: Telnet130: 2 2 251 3
*Mar 1 00:05:25.199: TCP130: Telnet sent WILL SUPPRESS-GA (3)
*Mar 1 00:05:25.199: Telnet130: 80000 80000 253 24
*Mar 1 00:05:25.203: TCP130: Telnet sent DO TTY-TYPE (24)
*Mar 1 00:05:25.203: Telnet130: 10000000 10000000 253 31
*Mar 1 00:05:25.203: TCP130: Telnet sent DO WINDOW-SIZE (31)
*Mar 1 00:05:25.315: TCP130: Telnet received DONT ECHO (1)
*Mar 1 00:05:25.315: TCP130: Telnet sent WONT ECHO (1)
*Mar 1 00:05:25.395: TCP130: Telnet received DONT SUPPRESS-GA (3)
*Mar 1 00:05:25.395: TCP130: Telnet sent WONT SUPPRESS-GA (3)
R1#
*Mar 1 00:05:25.399: TCP130: Telnet received WONT TTY-TYPE (24)
*Mar 1 00:05:25.399: TCP130: Telnet sent DONT TTY-TYPE (24)
*Mar 1 00:05:25.399: TCP130: Telnet received WONT WINDOW-SIZE (31)
*Mar 1 00:05:25.403: TCP130: Telnet sent DONT WINDOW-SIZE (31)
*Mar 1 00:05:25.483: TCP130: Telnet received DONT ECHO (1)
*Mar 1 00:05:25.699: TCP130: Telnet received DONT SUPPRESS-GA (3)
*Mar 1 00:05:25.699: TCP130: Telnet received WONT TTY-TYPE (24)
*Mar 1 00:05:25.699: TCP130: Telnet received WONT WINDOW-SIZE (31)

The telnet is working fine without the script from the same machine. Below is the debug for that:

*Mar 1 00:04:16.911: Telnet130: 1 1 251 1
*Mar 1 00:04:16.911: TCP130: Telnet sent WILL ECHO (1)
*Mar 1 00:04:16.911: Telnet130: 2 2 251 3
*Mar 1 00:04:16.911: TCP130: Telnet sent WILL SUPPRESS-GA (3)
*Mar 1 00:04:16.911: Telnet130: 80000 80000 253 24
*Mar 1 00:04:16.915: TCP130: Telnet sent DO TTY-TYPE (24)
*Mar 1 00:04:16.915: Telnet130: 10000000 10000000 253 31
*Mar 1 00:04:16.915: TCP130: Telnet sent DO WINDOW-SIZE (31)
*Mar 1 00:04:16.935: TCP130: Telnet received DO SUPPRESS-GA (3)
*Mar 1 00:04:16.935: TCP130: Telnet received WILL TTY-TYPE (24)
*Mar 1 00:04:16.935: Telnet130: Sent SB 24 1
*Mar 1 00:04:16.939: TCP130: Telnet received WILL WINDOW-SIZE (31)
*Mar 1 00:04:16.939: TCP130: Telnet received WILL TTY-SPEED (32) (refused)
*Mar 1 00:04:16.939: TCP130: Telnet sent DONT TTY-SPEED (32)
*Mar 1 00:04:16.939: TCP130: Telnet received WILL LOCAL-FLOW (33)
*Mar 1 00:04:16.943: TCP130: Telnet sent DO LOCAL-FLOW (33)
*Mar 1 00:04:16.943: Telnet130: Sent SB 33 0
*Mar 1 00:04:16.943: TCP130: Telnet received WILL LINEMODE (34)
*Mar 1 00:04:16.947: TCP130: Telnet sent DONT LINEMODE (34) (unimplemented)
*Mar 1 00:04:16.947: TCP130: Telnet received WILL NEW-ENVIRON (39)
*Mar 1 00:04:16.947: TCP130: Telnet sent DONT NEW-ENVIRON (39) (unimplemented)
*Mar 1 00:04:16.951: TCP130: Telnet received DO STATUS (5)
*Mar 1 00:04:16.951: TCP130: Telnet sent WONT STATUS (5) (unimplemented)
*Mar 1 00:04:16.951: TCP130: Telnet received WILL X-DISPLAY (35) (refused)
*Mar 1 00:04:16.955: TCP130: Telnet sent DONT X-DISPLAY (35)
*Mar 1 00:04:17.039: TCP130: Telnet received DO ECHO (1)
*Mar 1 00:04:17.039: Telnet130: recv SB NAWS 80 24
*Mar 1 00:04:17.043: Telnet130: recv SB 24 0 xterm-256color

Your inputs on this would be highly appreciated.

Regards,
DILRAJ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.