Unable to ping from Pycharm to the routers in GNS3 vian MS Loopback adapter

已回答

Hi,

1) I have installed MS Loopback adapter, assigned it 1.1.1.1/24

2) On router assigned  1.1.1.2/24

3) I am able to ping router from host PC (win10) by just opening cmd prompt. Below is the output

C:\Users\abc>ping 192.168.2.101

Pinging 192.168.2.101 with 32 bytes of data:
Reply from 192.168.2.101: bytes=32 time=3ms TTL=255
Reply from 192.168.2.101: bytes=32 time=2ms TTL=255
Reply from 192.168.2.101: bytes=32 time=3ms TTL=255

Ping statistics for 192.168.2.101:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 3ms, Average = 2ms

4) From pycharm and I am getting the below error:

* Ping to the following device has FAILED: 192.168.2.101

* Please re-check IP address list or device.


Process finished with exit code 0

5) Code is below. Can somebody please explain? 

import paramiko
import threading
import os.path
import subprocess
import datetime
import time
import sys
import re

def ip_is_valid():
check = False
global ip_list

while True:
try:
ip_file = input("Enter the filename and extension: ")
selected_ip_file = open(ip_file, 'r')
selected_ip_file.seek(0)
ip_list = selected_ip_file.readlines()
print(ip_list)
selected_ip_file.close()

except IOError:
print("File %s not found. Try Again!\n" % ip_file)
continue

for ip in ip_list:
a = ip.split('.')

if (len(a) == 4) and (1 <= int(a[0]) <= 223) and (int(a[0]) != 127) and (int(a[0]) != 169 or int(a[1]) != 254) and (0 <= int(a[1]) <= 254 and 0 <= int(a[2]) <= 254 and 0 <= int(a[3]) <= 254):
check = True
break
else:
print("Invalid IP found, please check\n")
check = False
continue

if check == False:
continue
elif check == True:
break


check2 = False
while True:
for ip in ip_list:
ping_reply = subprocess.call(['ping', ip], stdout = subprocess.PIPE)

if ping_reply == 0:
check2 = True
continue

elif ping_reply == 2:
print("\n* No response from device %s." % ip)
check2 = False
break

else:
print("\n* Ping to the following device has FAILED:", ip)
check2 = False
break

# Evaluating the 'check' flag
if check2 == False:
print("* Please re-check IP address list or device.\n")
sys.exit()

elif check2 == True:
print("\n* All devices are reachable. Checking SSHv2 connection file...\n")
break

ip_is_valid()

 

0
Avatar
Permanently deleted user

I guess the question is not really related to PyCharm. Does it work as you expect when you run it from the Windows command line using your Python interpreter?

0

请先登录再写评论。