title: Change last octet of IP address
body: <p>With the below code I fetch the IP address from a text file which contains list of IP addresses. Then SSH into Cisco Router to make changes that is common to all the devices. This time however I have to make changes that are variable in nature.</p>
  
  <p><strong>Example:</strong></p>
  
  <p>I have to fetch the ip address (10.120.15.1) and SSH into the device and apply the following command</p>
  
  <p>"access-list 150 permit ip <strong>10.120.15.0</strong> 0.0.0.255 host 10.100.100.1"</p>
  
  <p>The IP address is already contained in the variable "line" and I have to split the last octet and change it from "1" to "0" and then insert to the access list.</p>
  
  <p>Please share your inputs.</p>
  
  <pre><code>import paramiko
  import sys
  import os
  import time
  import cmd
  
  buff = ''
  resp = ''
  
  with open('Address.txt', 'r') as f:
      for line in f:
          line = line.strip()
          dssh = paramiko.SSHClient()
          dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
          dssh.connect(line, username='cisco', password='cisco')
          chan = dssh.invoke_shell()
          chan.send('conf t\n')
          time.sleep(1)
          resp = chan.recv(9999)
          chan.send('access-list 150 permit ip X.X.X.X 0.0.0.255 host 10.100.100.1\n exit\n')
          time.sleep(1)
          resp = chan.recv(9999) 
   dssh.close()
  </code></pre>