Last active
February 8, 2017 16:06
-
-
Save toast254/714316bea4266fba1c08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: UTF-8 -*- | |
import sys | |
import requests # http://docs.python-requests.org/en/master/ | |
from bs4 import BeautifulSoup # http://www.crummy.com/software/BeautifulSoup/ | |
# OpenNIC url | |
url = 'https://servers.opennicproject.org' | |
# proxies | |
proxies = {} | |
#proxies = {'http': '127.0.0.1:3128', 'https': '127.0.0.1:3128'} # <-- example simple HTTP proxy | |
#proxies = {'http': 'socks5://127.0.0.1:8080', 'https': 'socks5://127.0.0.1:8080'} # <-- example with SockV5 proxy (pip install -U pysocks) | |
# DNS are not proxified ! | |
# init result vars | |
ip_v4 = [] | |
ip_v6 = [] | |
# request | |
r = requests.get(url=url, proxies=proxies) | |
# good response ? | |
if r.status_code == 200: | |
# parse response | |
bs = BeautifulSoup(r.text, "html.parser") | |
# find all running servers | |
server_list = bs.find_all('p', class_='norm') | |
# is there at least one ? | |
if len(server_list) > 0: | |
# for each one | |
for server in server_list: | |
# find ipv4 | |
ipv4 = str(server.find('span', class_='ipv4').text).strip() | |
ipv6 = str(server.find('span', class_='ipv6').text).strip() | |
if ipv4: | |
ip_v4.append(ipv4) | |
if ipv6: | |
ip_v6.append(ipv6) | |
else: # no one running ... | |
print('No running server !', file=sys.stderr) | |
sys.exit(-2) | |
else: # not a good response | |
print('Error receiving from : ' + url, file=sys.stderr) | |
sys.exit(-1) | |
# show ipv4 list | |
print('ipv4 :') | |
for ipv4 in ip_v4: | |
print(ipv4) | |
# | |
print() | |
# show ipv6 list | |
print('ipv6 :') | |
for ipv6 in ip_v6: | |
print(ipv6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment