dimanche 3 mai 2015

Java Regex: How to extract ip address except the last part from the string?

I am experimenting with websockets and i want to make it connect to local network automatically from other computer on the LAN and since there are 255 possible computers on the same network i want it to try all and then connect to whichever it can connect to first . However, first part of ip addresses, 192.168.1.* is different based on what settings you have router.

I can get the whole current ip address of the machine, then i want to Extract the front part.

For ex..

25.0.0.5 will become 25.0.0.
192.168.0.156 will become 192.168.0.
192.168.1.5 will become 192.168.1.

and so on

 String Ip  = "123.345.67.1";
 //what do i do here to get Ip == "123.345.67."

Aucun commentaire:

Enregistrer un commentaire