Skip to content

Instantly share code, notes, and snippets.

@sinnlosername
Last active January 2, 2018 03:56
Show Gist options
  • Save sinnlosername/0ba5a62451214786fa24cdfc33c95899 to your computer and use it in GitHub Desktop.
Save sinnlosername/0ba5a62451214786fa24cdfc33c95899 to your computer and use it in GitHub Desktop.
Simple Go Code to check if an ip is a tor exit node
package torcheck
import (
"net"
"net/http"
"log"
"bufio"
"strings"
)
var torNodes = make([]net.IP, 0)
func UpdateTorNodes() {
resp, err := http.Get("https://check.torproject.org/exit-addresses")
if err != nil {
log.Panicf("Unable to update list: %v", err)
}
defer resp.Body.Close()
for s := bufio.NewScanner(resp.Body); s.Scan(); {
line := s.Text()
if !strings.HasPrefix(line, "ExitAddress") {
continue
}
if ip := net.ParseIP(strings.Split(line, " ")[1]); ip != nil {
torNodes = append(torNodes, ip)
continue
}
}
}
func CheckIP(ip net.IP) bool {
for _, elem := range torNodes {
if elem.Equal(ip) {
return true
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment