Java examples for Network:IP Address
Generate a random ipv4 address in the 10.0.0.0/8 range.
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getRandomIpv4Address()); }//w ww.j a v a 2 s . c o m /** * Generate a random ipv4 address in the 10.0.0.0/8 range. * @return A string form of the ipv4 address in the 10.0.0.0/8 range. */ public static String getRandomIpv4Address() { return "10." + (int) (Math.random() * 255) + "." + (int) (Math.random() * 255) + "." + (int) (Math.random() * 255); } }