|
8 | 8 | - updates the IP address on the interface
|
9 | 9 | - displays the final IP information on the interface
|
10 | 10 |
|
11 |
| - This script has been tested with Python 3.5, however may work with other versions. |
| 11 | + This script has been tested with Python 3.7, however may work with other versions. |
12 | 12 |
|
13 | 13 | This script targets the RESTCONF DevNet Sandbox that leverages a CSR1000v as
|
14 | 14 | a target. To execute this script against a different device, update the
|
@@ -120,7 +120,7 @@ def print_interface_details(url_base, interface, username, password, cidr):
|
120 | 120 | netmask = intf[0]["ietf-ip:ipv4"]["address"][0]["netmask"]
|
121 | 121 | if cidr:
|
122 | 122 | nma = ipaddress.ip_address(netmask)
|
123 |
| - netmask = str("{0:b}".format(nma._ip).count('1')) |
| 123 | + netmask = str("{0:b}".format(int(nma)).count('1')) |
124 | 124 | print("IP Address: ", intf[0]["ietf-ip:ipv4"]["address"][0]["ip"], "/",
|
125 | 125 | netmask)
|
126 | 126 | except KeyError:
|
@@ -156,14 +156,17 @@ def get_ip_info(cidr):
|
156 | 156 | ip = {}
|
157 | 157 | try:
|
158 | 158 | if cidr:
|
159 |
| - (ipa_t, ipl) = input("What IP address/prefixlen do you want to set? ").split('/') |
160 |
| - ipa = ipaddress.ip_address(ipa_t) |
161 |
| - ip["address"] = ipa.compressed |
162 |
| - ip["mask"] = ipa._make_netmask(int(ipl))[0].compressed |
| 159 | + ipa_t = input("What IP address/prefixlen do you want to set? ") |
| 160 | + ipi = ipaddress.ip_interface(ipa_t) |
| 161 | + ip["address"] = ipi.ip.compressed |
| 162 | + ip["mask"] = ipi.netmask.compressed |
163 | 163 | else:
|
164 | 164 | ipa_t = input("What IP address do you want to set? ")
|
165 |
| - ip["address"] = ipaddress.ip_address(ipa_t).compressed |
166 |
| - ip["mask"] = input("What Subnet Mask do you want to set? ") |
| 165 | + ipi = ipaddress.ip_interface(ipa_t) |
| 166 | + ip["address"] = ipi.ip.compressed |
| 167 | + ipm_t = input("What Subnet Mask do you want to set? ") |
| 168 | + ipm = ipaddress.ip_address(ipm_t) |
| 169 | + ip["mask"] = ipm.compressed |
167 | 170 | except Exception as e:
|
168 | 171 | print(e, file=sys.stderr)
|
169 | 172 | sys.exit(1)
|
|
0 commit comments