in reply to How can I change web address into its IP's ?

OK, a coulple of basic things first. If I am "teaching you how to suck eggs", then my apologies.

Firstly, a URL consists up up to four components. Take this as an example:

http://www.dummyurl.com.au/directory/index.html?question=how
The parts are: (these are my own names - there is probably the "official" ones in an RFC somewhere)
  1. Protocol - the "http:" section. You can also see URL's starting with "ftp:" or "telnet:" and so on. This means we will use http as the transfer protocol.
  2. host and domain name - the "www.dummyurl.com.au". Somewhere there is a domain name "dummyurl.com.au". If you have access to a unix shell account, try nslookup. Read up about DNS - the Domain Name Service - that translates names to addresses. The "www" is a host connected to that domain, and has been the default web server host name. It doesn't have to be that tho.
  3. The file name - directory/index.html. Starting at the web server's "document root" directory, there will be a subdirectory "directory" containing a file "index.html". This is the html document that is returned to you.
  4. cgi "get" paramaters - the bit ?question=how. These are values that a "get" request will pass to a cgi program.
Now, there are much more detailed and complete descriptions of URLs that that, but I think you get the picture. So what you are wanting to do is to turn the domain name part in to its corresponding ip address. There are modules that can do that - Net::DNS is your friend here.

One question though is - why? Why do you need to know that "yahoo.com" has an ip address of 10.10.10.10? That may very well change tomorrow, but the name will remain (relatively) constant.

Replies are listed 'Best First'.
Re (tilly) 2: How can I change web address into its IP's ?
by tilly (Archbishop) on Apr 11, 2001 at 15:49 UTC
    You forgot the optional name/password. :-)
Re: Re: How can I change web address into its IP's ?
by knobunc (Pilgrim) on Apr 11, 2001 at 20:48 UTC

    Very informative post.

    I just wanted to point out the URI module is excellent if you need to break apart a URI (a susperset of URL and URN). It handles all of the odd syntax that Maclir posted above. You can just do:

    use URI; use Socket; my $url = "http://www.yahoo.com/whatever/foo?bar=baz # Get the host out of the URL string my $uri = URI->new($url); my $host = $url->host; # Get the IP address for the host my $packed_ip = gethostbyname($host) or die "Unable to resolve '$host'\n"; my $ipaddr = inetntoa($packed_ip); print "Got '$ipaddr' for host '$host'\n";

    Another gotcha is that the IP addresses can revolve. So www.yahoo.com resolves to 9 addresses. My code above does not take that into account so if you want to know all of the addresses you will need to use Net::DNS. This multiple 'round-robin' address resolution is a common way of implementing load balancing. Your resolver will pick one of the addresses at random so you will only connect to one server, but other people will get a different server so on average the load will be sort of balanced across all of the machines.

    As you can see DNS is not exacly simple. So what are you really trying to do?

    -ben