Below is my working code which is used to show my router arp table on Cisco Routers.
I have a task at my hand which requires me to read specific values from the output of the "sh arp " command and use it as input for another command to be executed on the Cisco router.
commands in the router:
1- sh arp vrf INTERNET | INC 0835.71
2- ping vrf INTERNET 100.124.162.230**
I have step 1 done . I can get the output but I need hep to get step 2 done, to capture the IP "100.124.162.230 run a ping to it.
print(" Pinging the NMD....")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("r-a" ,timeout = 10)
chan = ssh.invoke_shell()
time.sleep(.1)
chan.send('sh arp vrf INTERNET | INC 0835.71 \n')
time.sleep(20)
#Print command output
while chan.recv_ready():
output = str(chan.recv(99999999))
output.encode('utf-8')
#print(type(output))
#print("\n\n\nPrinting total output: {0}".format(output))
output:
r-a>sh arp vrf INTERNET | INC 0835.71 Internet 100.124.162.230 74 0835.71ef.d0a1 ARPA GigabitEthernet0/0.901
2- Next step is to get the IP and run a ping to it please help.
I extracted my IP address, now I want to run a ping to the extracted IP, HOW can I do this in python. Please help ..
r-a>sh arp vrf INTERNET | inc 0835 Internet 100.114.162.230 110 0835.71ef.d0a1 ARPA GigabitEthernet0/0.901 r-a.> ['100.114.162.230']
ssh.connect("r-a" + name + ".us", username = 'cisco', password = '1234', timeout = 10)
chan = ssh.invoke_shell()
time.sleep(.1)
chan.send('sh arp vrf INTERNET' + ' ' + '|'+ ' ' + 'inc 0835' '\n')
time.sleep(2)
chan.send('ping' + ' ' + 'ip' '\n' )
#Print command output
while chan.recv_ready():
output = str(chan.recv(99999999))
output.encode('utf-8')
print("\n\n\nPrinting total output: {0}".format(output))
ip = re.findall(r'100.\d+\d+.\d+.\d',output)
print(ip)