Skip to content

Instantly share code, notes, and snippets.

@zealic
Created December 12, 2014 06:57
Show Gist options
  • Save zealic/adb4502b504c95d1549e to your computer and use it in GitHub Desktop.
Save zealic/adb4502b504c95d1549e to your computer and use it in GitHub Desktop.
Override Java DNS Name Server
#!/usr/bin/bash
NAME=CustomDns
cat > $NAME.java <<EOF
import java.net.*;
import java.io.*;
class $NAME {
public static void main(String[] args) throws Exception {
System.setProperty("sun.net.spi.nameservice.nameservers", "127.0.0.1,114.114.114.114");
//System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");
String hostname = "example.org";
if(args.length > 0) {
hostname = args[0];
}
InetAddress addr = InetAddress.getByName(hostname);
System.out.println(addr.toString());
}
}
EOF
javac $NAME.java
java $NAME $@
rm $NAME.java $NAME.class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment