Skip to content

Instantly share code, notes, and snippets.

@jjsantanna
Created October 20, 2018 09:27
Show Gist options
  • Save jjsantanna/9cad79aee4b4c78b2c13719d2ef75794 to your computer and use it in GitHub Desktop.
Save jjsantanna/9cad79aee4b4c78b2c13719d2ef75794 to your computer and use it in GitHub Desktop.
Wildcard IP of reserved IPs
### CRAWLER wikipedia for reserved IPs
import cfscrape
from lxml import etree
import pandas as pd
url="https://en.wikipedia.org/wiki/Reserved_IP_addresses"
scraper = cfscrape.create_scraper()
scraped_html=scraper.get(url).content
tables = pd.read_html(scraped_html) # Returns list of all tables on page
reserved_ipv4=tables[0][0].drop(0)
reserved_ipv6=tables[1][0].drop(0)
########################
### WILDCARD IPS
import ipaddress
network = '192.168.0.0/16'
ips = ipaddress.IPv4Network(network)
first_ip = str(ips[0]).split('.')
last_ip = str(ips[-1]).split('.')
print('first ip: ',first_ip)
print('last ip: ',last_ip)
first_octet = list([first_ip[-4]])
second_octet = list([first_ip[-3]])
third_octet = list([first_ip[-2]])
fourth_octet = list([first_ip[-1]])
if first_ip[-1]=='0' and last_ip[-1] == '255':
fourth_octet = ['*']
if first_ip[-2]=='0' and last_ip[-2] == '255':
third_octet = ['*']
if first_ip[-3]=='0' and last_ip[-3] == '255':
second_octet=['*']
if first_ip[-4]=='0' and last_ip[-4] == '255':
first_octet=['*']
else:
first_octet = list(range(int(first_ip[-4]), int(last_ip[-4])+1))
else:
second_octet = list(range(int(first_ip[-3]), int(last_ip[-3])+1))
else:
third_octet = list(range(int(first_ip[-2]), int(last_ip[-2])+1))
else:
fourth_octet = list(range(int(first_ip[-1]), int(last_ip[-1])+1))
print('list of octets (4 combining): ',first_octet,second_octet,third_octet,fourth_octet)
for element1 in first_octet:
if second_octet != ['*']:
for element2 in second_octet:
print (str(element1)+'.'+str(element2)+'.*')
if third_octet != ['*']:
for element3 in third_octet:
print (str(element1)+'.'+str(element2)+'.'+str(element3)+'.*')
if fourth_octet != ['*']:
for element4 in fourth_octet:
print (str(element1)+'.'+str(element2)+'.'+str(element3)+'.'+str(element4))
else:
print (str(element1)+'.*')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment