Last active
January 2, 2018 03:56
-
-
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
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
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