Skip to content

Instantly share code, notes, and snippets.

@kisom
Created June 16, 2013 17:08
Show Gist options
  • Save kisom/5792690 to your computer and use it in GitHub Desktop.
Save kisom/5792690 to your computer and use it in GitHub Desktop.
scripts to fetch OpenNICProject nameservers, suitable for putting in resolv.conf.
package main
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"os"
"regexp"
"strings"
)
const ONPSite = "http://opennicproject.org/"
var addrRegexp = regexp.MustCompile("((?:\\d{1,3}\\.){3}\\d{1,3})")
func main() {
var doc *goquery.Document
var err error
if doc, err = goquery.NewDocument(ONPSite); err != nil {
fmt.Println("[!] failed to load document:", err.Error())
os.Exit(1)
}
sel := doc.Find("h4").First().Text()
selLns := strings.Split(sel, "\n")
for _, line := range selLns {
if addr := addrRegexp.FindString(line); addr != "" {
fmt.Println("nameserver", addr)
}
}
}
#!/usr/bin/env python
"""Retrieve nameservers from the OpenNIC Project."""
import BeautifulSoup
import requests
import re
ONP_SITE = "http://opennicproject.org"
def pour_soup():
"""Grab the relevant text out of the page."""
req = requests.get(ONP_SITE)
if req.status_code is not 200:
return None
soup = BeautifulSoup.BeautifulSoup(req.content)
return soup.find('h4').text.split('\n')
def consume_soup(soup):
"""Builds a list of all IPv4 addresses found."""
addrs = []
grep = r'((?:[0-9]{1,3}\.){3}[0-9]{1,3})'
for line in soup:
match = re.search(grep, line)
if match is None:
continue
addrs.append(match.groups()[0])
return addrs
if __name__ == '__main__':
for addr in consume_soup(pour_soup()):
print 'nameserver', addr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment