[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] How to get the IP address ?



At 11:13 pm +0200 08.04.97, Lemarchand wrote:
>I want to build a HTTP server but my provider can not give me any fix IP
>address.

If I recall correctly, one of the strengths of the HTTP/1.1 protocol is
that it should let you run a server without the need for a fixed IP
address. On the other hand, it depends on the client sending you the
'Host:' field, and not all of them do that yet. Plus you need a unique
domain name (this is going to be a continuing refrain in this message) So
that probably won't help.

>* Having a fix URL (at geocities for example) where I will have
>  a link to my personnal web server. This link will be automatically
>  updated (by an upload) each time my web server will be connected

One awkward thing is that, as far as I can remember, GeoCities discourage
you from doing that. If you read:

	http://www.geocities.com/homestead/homeguide.html

you'll see that they ask you to 'refrain from':

	Using your page (or directory) as storage for remote loading
	or as a door or signpost to another server

Some of the other free homepage services may not have this restriction.

>* Having an automatic procedure on my web server connection that
>  would get the dynamic IP address for this connection and upload
>  the correction at my geocities address.

If your server has a unique domain name, then the Perl command
'gethostbyname()' may allow you to get the IP address. However, it will
rather depend on how your provider handles things. You may want to try out
the following snippet:

  $myhostname = "foo.com";
  ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($myhostname);
  foreach (@addrs) {
     ($a,$b,$c,$d) = unpack('C4',$_);
     print "$a.$b.$c.$d\n";
  }

in MacPerl while you're connected to the server (substituting 'foo.com' by
whatever your machine is called). Try it on several different connections;
if you get a different IP address each time, then that suggests that you
may have found the way to determine the IP number for your connection.

If this doesn't work, or you don't have a domain name of your own, (i.e.
you're 'joe_user@bigprovider.com', rather than
'me@joe_user.bigprovider.com'), you may have to try opening a socket and
seeing if you can extract your IP number from that somehow. Read the
documentation for 'Socket.pm', which is the next best thing to totally
incomprehensible, but may contain the answer to your question. From a
cursory glance, I can't work out if you need to know your own IP address in
advance before opening a connection, or if that will fall out automatically
from the 'connect' process.

Uploading will probably require you to use an FTP module from CPAN (there
must be one). You build the redirection page from a template using Perl,
squirt in the IP number you've recovered, and upload it to your chosen
'front-end' site. Using the right module, it shouldn't be *too* gnarly.

The whole process seems rather awkward to me, though. Too much can
potentially go wrong (what if you can't upload to your 'front-end' site for
some reason?). If you're physically connected to a T1, I find it hard to
believe that your provider can't offer you a permanent IP address or a
unique domain name (if you have a unique domain name, there ought to be a
way for visitors to get back to a valid IP address through your provider's
DNS). They may charge extra, but it will probably be worth it in terms of
ease of use.

Just my 2c.

		A

--
angus@pobox.com                             http://pobox.com/~angus

"I'm stubborn as those garbage bags that time will not decay.   "Democracy"
 I'm junk but I'm still holding out my little wild bouquet."   Leonard Cohen



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch