Comments (16)
Try using
HOST = line.strip()
It is working for me
from pythonvideos.
@davidbombal I am getting the similar problem and error when running the for loop script using myswitch file any suggestion ?
Traceback (most recent call last):
File "diffip.py", line 13, in
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
from pythonvideos.
Port timeout is happening, can you normally telnet to the switches.
from pythonvideos.
Hello,
I am new to Python coding and was following David's video on this script.
Even I am getting the same error.
Tried changing the HOST = line.strip() but in vain.
Below is my code:
import getpass
import sys
import telnetlib
import socket
fd = open("C:\Users\user\Desktop\PYTHON\HOME\IP_List.txt")
for line in fd:
user = "mandeep"
password = "cisco"
print "Configuring Routers: " + (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("term len 0\n")
tn.write("sh ip int brief \n")
tn.write("exit\n")
print tn.read_all()
#print (output)
#with open("Health.csv", "wb") as f:
#f.write(output)
from pythonvideos.
@Mandeep4code Check if it working with a single Host first.
from pythonvideos.
Hello, Guys
Try using this form:
It is working for me.
import getpass
import telnetlib
import sys
user = raw_input("Enter your Telnet Username ")
password = getpass.getpass()
f = open('myrouters')
all_ips = [x.rstrip() for x in f]
for line in all_ips:
print ("Configuring Switch " + (line))
HOST = line
tn = telnetlib.Telnet(HOST)
tn.read_until("Username: ")
tn.write(user.encode('ascii') + "\n")
if password:
tn.read_until("Password: ")
tn.write(password.encode('ascii') + "\n")
tn.write("config 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("wr\n")
tn.write("exit\n")
print(tn.read_all().decode('ascii'))
from pythonvideos.
I tried everything posted here still same error as martinhoeegh and dazzy099. I tried to manually telnet and it works. Even if I use the same code and with single ip address on the code without using the file open it works fine.
Can someone please help me
from pythonvideos.
try HOST=line.strip() it worked for me
from pythonvideos.
Has anyone ever figured this out? I am having the same problem.
from pythonvideos.
i had the same issue,
HOST = line.strip() works
from pythonvideos.
Has anyone ever figured this out? I am having the same problem.
HOST = line.strip() works
from pythonvideos.
does anyone know why we have to use .strip() to get it working?
from pythonvideos.
To some one who landed to this page like how I did for the code that I was facing the issue.
In short :
HOST = line.strip() works
Here is the right script that works:
#!/usr/bin/env python
import getpass
import sys
import telnetlib
user = raw_input("Enter your username: ")
password = getpass.getpass()
f = open ('myswitches')
for line in f:
print "Configuring Switch " + (line)
HOST = line.strip()
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,26):
tn.write("vlan " + str(n) + "\n")
tn.write("name Python_VLAN_" + str(n) + "\n")
tn.write("end\n")
tn.write("exit\n")
print tn.read_all()
In case of further queries please write to me at [email protected]
Youtube channel for Network automations - https://www.youtube.com/playlist?list=PLtFe0r3PejgnDmMTbFupLxlXTMkFtZGwh
from pythonvideos.
Tried line.strip () and received the same error, copied the exact code from sagar and tested and same error
Traceback (most recent call last):
File "./teststuff", line 15, in
tn = telnetlib.Telnet(HOST)
File "/usr/lib/python2.7/telnetlib.py", line 211, in init
self.open(host, port, timeout)
File "/usr/lib/python2.7/telnetlib.py", line 227, in open
self.sock = socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -3] Temporary failure in name resolution
root@UbuntuDockerGuest-1:~#
from pythonvideos.
Have you tried with a single host first?
from pythonvideos.
Try using
HOST = line.strip()It is working for me
yes, thank you
it works \m/
from pythonvideos.
Related Issues (11)
- teste
- my experience with pythonR1script1.py HOT 3
- GNS3 Talks: Python for Network Engineers with GNS3 (Part 5) - Multiple switches, multiple VLANs - ISSUE
- Центр учетных записей Wondershare
- Missing 'iosv_l2_core' file for netmiko6.py HOT 1
- Missing 'iosv_l2_access' file for netmiko6.py HOT 1
- did not get last host HOT 1
- Unable to Telnet "Telnet received DONT Echo (1)" HOT 2
- ACL find and add project - Network Scripting
- Netmiko/Paramiko SSH issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pythonvideos.