Skip to content

Instantly share code, notes, and snippets.

@zwetan
Last active August 29, 2015 14:07
Show Gist options
  • Save zwetan/0c047d36542cc6979652 to your computer and use it in GitHub Desktop.
Save zwetan/0c047d36542cc6979652 to your computer and use it in GitHub Desktop.
obtain all the IP addresses of a hostname
import C.errno.*;
import C.arpa.inet.*;
import C.netdb.*;
import C.sys.socket.*;
import C.stdlib.*;
import C.unistd.*;
var hostname:String = "www.google.com";
trace( "hostname = " + hostname );
var hints:addrinfo = new addrinfo();
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_UNSPEC;
var eaierr:CEAIrror = new CEAIrror();
var addrlist:Array = getaddrinfo( hostname, "http", hints, eaierr );
if( !addrlist )
{
trace( eaierr );
exit(0);
}
trace( "found " + addrlist.length + " addresses" );
var i:uint;
var info:addrinfo;
for( i = 0; i < addrlist.length; i++ )
{
//trace( "addrlist[" + i + "] = " + addrlist[i] );
info = addrlist[i];
trace( "[" + i + "] = " + inet_ntop( info.ai_family, info.ai_addr ) );
}
//output
/*
hostname = www.google.com
found 6 addresses
[0] = 74.125.71.99
[1] = 74.125.71.104
[2] = 74.125.71.105
[3] = 74.125.71.106
[4] = 74.125.71.147
[5] = 74.125.71.103
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment