我正在尝试使用以下javascript随机方法创建假IP address
。但不行。
任何人都帮我找到正确的方法吗?
这是我的尝试:我看起来像("192.168.10.2"
)
console.log( Math.random(256) + "." + Math.random(256) + "." + Math.random(256) + "." + Math.random(256) );
答案 0 :(得分:9)
代码应为:
var ip = (Math.floor(Math.random() * 255) + 1)+"."+(Math.floor(Math.random() * 255) + 0)+"."+(Math.floor(Math.random() * 255) + 0)+"."+(Math.floor(Math.random() * 255) + 0);
console.log(ip)
代码(Math.floor(Math.random() * 255) + 1)
表示生成1到255之间的随机数。