【问题标题】:Creating fake IP address Using Javascript [duplicate]使用Javascript创建假IP地址[重复]
【发布时间】:2017-09-13 20:10:55
【问题描述】:

我正在尝试使用以下 javascript 随机方法创建假 IP address。但不起作用。

有人帮我找到正确的方法吗?

这是我的尝试:我看起来像 ("192.168.10.2")

 console.log(  Math.random(256) + "." + Math.random(256) + "." + Math.random(256) + "." + Math.random(256) );

【问题讨论】:

    标签: javascript random


    【解决方案1】:

    代码应该是:

    var ip = (Math.floor(Math.random() * 255) + 1)+"."+(Math.floor(Math.random() * 255))+"."+(Math.floor(Math.random() * 255))+"."+(Math.floor(Math.random() * 255));
    console.log(ip)

    代码(Math.floor(Math.random() * 255) + 1)表示生成一个1到255之间的随机数。

    【讨论】:

    • 在我看来,链接为重复的问题只是在某些方面相似。
    猜你喜欢
    • 2014-01-25
    • 2012-01-24
    • 2012-07-18
    • 2012-12-05
    • 1970-01-01
    • 2014-04-27
    • 2011-06-29
    • 2011-03-17
    • 1970-01-01
    相关资源
    最近更新 更多