Commit 4e67f2ef by vince

initial

parent 122f2cbf
......@@ -2,3 +2,31 @@ open-nic
========
Use open-nic DNS right now
What is open-nic and why should I use it ?
=================
The Opennic project is an alternative DNS provider.
You should use it if you're concerned about censorship, if you don't
want your internet provider to know every site you visit, if you want
to support independant projects, maybe if you want to access .geek,
.indy, .free and other sites.
http://www.opennicproject.org/
https://en.wikipedia.org/wiki/OpenNIC
How to use this script
======================
Simply call
python open-nic-get.py
(you should ensure the DNS servers are not in the same location)
it will configure your configuration file with the three DNS servers
that suit you best. They are taken from their page: http://www.opennicproject.org/nearest-servers/
A restart may be needed.
You can undo the operation:
python open-nic-undo.py
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
CONF = "/etc/dhcp3/dhclient.conf"
if not os.path.isfile(CONF):
exit(0)
if os.path.isfile(CONF + ".back"):
shutil.move(CONF + ".back", CONF)
import requests
try:
from bs4 import BeautifulSoup
except:
print 'you need to install BeautifulSoup4: '
print "sudo pip install BeautifulSoup4"
exit(1)
import re
import os
import shutil
"""
Use dns servers of the open-nic project.
Fetch which are the nearest dns servers and insert them into dhclient.conf file.
"""
CONF = "/etc/dhcp3/dhclient.conf"
r = requests.get('http://www.opennicproject.org/nearest-servers/')
nic = BeautifulSoup(r.text)
assert nic
nearest = nic.find_all('div', class_='post-entry')
assert nearest[0]
dns_text = nearest[0].find('p')
assert dns_text.text
dns_list = re.findall('\d+\.\d+\.\d+\.\d+', dns_text.text)
print "nearest dns list: ", dns_list
if os.path.exists(CONF):
shutil.copyfile(CONF, CONF + ".back")
with open(CONF, 'a') as f:
# with open('foobar.txt', 'a') as f:
w = "\nprepend domain-name-servers " + ", ".join(s for s in dns_list[:3]) + ";"
print "we add the line: " + w + " to the file " + CONF
print "we saved the original conf file, so if you notice any connection pb, you can still put it back"
f.write(w)
#todo: proposer un «undo»: remettre le .back en place
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment