集册 Java实例教程 生成10.0.0.0/8范围内的随机ipv4地址。

生成10.0.0.0/8范围内的随机ipv4地址。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

446
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
生成10.0.0.0/8范围内的随机ipv4地址。
/* 来自 nowjava*/


//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        System.out.println(getRandomIpv4Address());

    }


    /**

     * 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) + "."

                + (
展开阅读全文