Schemaphic Systems Blog

Sharing experiences in Flash, Flex and AIR

Genarate IP addresses randomly

leave a comment »

function getIP(decimal:Number):String {
var IP1 = Math.floor(decimal/Math.pow(256,3));
var IP2 = Math.floor((decimal%Math.pow(256,3))/Math.pow(256,2));
var IP3 = Math.floor(((decimal%Math.pow(256,3))%Math.pow(256,2))/Math.pow(256,1));
var IP4 = Math.floor((((decimal%Math.pow(256,3))%Math.pow(256,2))%Math.pow(256,1))/Math.pow(256,0));
var ip = IP1+”.”+IP2+”.”+IP3+”.”+IP4;
return ip;
}
function generateIP():String {
return getIP((Math.random()*(256*256*256*256 -1)));
}
trace( generateIP() );

Advertisements

Written by Deepanjan Das

July 12, 2010 at 9:20 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: