Last active
August 29, 2015 14:07
-
-
Save hourback/3832f4baa1d8ccc3e200 to your computer and use it in GitHub Desktop.
Static routes for routing certain requests through friendlier interfaces. The first file is the Windows batch file I originally used, and the second it the Go program I wrote to do the lookup dynamically.
This file contains hidden or 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
REM archive.ubuntu.com | |
route add 91.189.92.201 mask 255.255.255.255 172.16.1.1 | |
route add 91.189.92.200 mask 255.255.255.255 172.16.1.1 | |
route add 91.189.91.15 mask 255.255.255.255 172.16.1.1 | |
route add 91.189.91.14 mask 255.255.255.255 172.16.1.1 | |
route add 91.189.91.13 mask 255.255.255.255 172.16.1.1 | |
route add 91.189.88.153 mask 255.255.255.255 172.16.1.1 | |
route add 91.189.88.149 mask 255.255.255.255 172.16.1.1 | |
REM pastebin.com | |
route add 190.93.241.15 mask 255.255.255.255 172.16.1.1 | |
route add 190.93.240.15 mask 255.255.255.255 172.16.1.1 | |
route add 190.93.243.15 mask 255.255.255.255 172.16.1.1 | |
route add 141.101.112.16 mask 255.255.255.255 172.16.1.1 | |
route add 190.93.242.15 mask 255.255.255.255 172.16.1.1 |
This file contains hidden or 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 main | |
import ( | |
"bytes" | |
"fmt" | |
"log" | |
"net" | |
"os" | |
"os/exec" | |
"runtime" | |
) | |
func main() { | |
if runtime.GOOS == "windows" { | |
fmt.Println("Great! Looks like we're running on Windows. Commencing to improve routing table. . . .") | |
} else { | |
fmt.Println("This program only runs on Windows for now. Exiting. . . .") | |
os.Exit(1) | |
} | |
var domains []string | |
if len(os.Args) == 1 { | |
domains = []string{"pastebin.com", "archive.ubuntu.com"} | |
} else { | |
domains = os.Args[1:] | |
} | |
for i := range domains { | |
domain := domains[i] | |
fmt.Println("\n\nWorking on domain ", domain) | |
// Do a single lookup | |
/* ip, err := net.ResolveIPAddr("ip4", domain) | |
if err == nil { | |
fmt.Printf("%s ok %s\n", domain, ip) | |
} else { | |
fmt.Printf("%s error: %s\n", domain, err) | |
}*/ | |
// Use LookupIP instead to get an array of IPs | |
ips, err := net.LookupIP(domain) | |
if err == nil { | |
for i := range ips { | |
ip := ips[i] | |
cmd := exec.Command("cmd", "/C", "route", "add", ip.String(), "mask", "255.255.255.255", "172.16.1.1") | |
var out bytes.Buffer | |
cmd.Stdout = &out | |
err := cmd.Run() | |
if err != nil { | |
log.Println("\n\nCommand failed:", out.String()) | |
log.Fatal(err) | |
} | |
fmt.Println("Added route for ", ip.String()) | |
} | |
} else { | |
fmt.Printf("\n\n%s error: %s\n", domain, err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment