I'm not sure how to go about this, my program is supposed to get the user to input an IP address. the program is then supposed to return a value in decimal notation. e.g 134.115.64.1 is input and 2255699969 is output.
I was wondering if i could store 134,115,64 and 1 in variable. if so, how could i go about it? A link to any sort of tutorial would be great as i haven't managed to find one my self.
Thanks
A trick for parsing IP addresses
BigInteger ip = new BigInteger(1,InetAddress.getByName("134.115.64.1").getAddress());
// or
long ip = InetAddress.getByName("134.115.64.1").hashCode() & 0xffffffffL;
System.out.println(ip);
prints
2255699969
You can do something like :
String str = "134.115.64.1";
String arr[] = str.split("\\.");
int[] ips = new int[arr.length];
for(int i=0; i<arr.length;i++)
ips[i] = Integer.parseInt(arr[i]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With