Created
December 12, 2014 06:57
-
-
Save zealic/adb4502b504c95d1549e to your computer and use it in GitHub Desktop.
Override Java DNS Name Server
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
#!/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