home / blog

Convert dotted IP to decimal IP – my comedy answer

String input = "134.115.64.1";
String sum = input.replaceAll("(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)",
        "($1 * 16777216) + ($2 * 65536) + ($3 * 256) + $4");
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");

double result = (Double) engine.eval(sum);
System.out.println((long) result);
This entry was posted in geek and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.