2017-04-18 3 views
-2

Ich versuche, gefälschte IP address mit der folgenden javascript Zufallsmethode zu erstellen. Aber funktioniert nicht.Erstellen gefälschte IP-Adresse mit Javascript

jemand mir helfen, den richtigen Weg zu bekommen, dies zu tun?

hier ist mein Versuch: Ich bin wie ("192.168.10.2")

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

Antwort

2

Der Code sollte:

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)

Der Code (Math.floor(Math.random() * 255) + 1) Mittel eine Zufallszahl zwischen erzeugen 1 und 255.

+0

Nur ein Zeiger. Es ist eine schlechte Übung, ein Duplikat zu beantworten. – Rajesh

Verwandte Themen