[Tutor] IP Address

dman dman@dman.ddts.net
Wed, 22 May 2002 14:23:47 -0500


--azLHFNyN32YCQGCU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, May 22, 2002 at 11:15:51AM -0700, Chad Crabtree wrote:
| I would like to make a script that Would FTP Post my
| home computer's IP address to my homepage.

How about using ddts or dyndns to have your computer post it's IP
address to a DNS server?  Those services provide a client-side daemon
that sends packets to the server with your IP address.  The server
then updates the DNS records so that your hostname points to your
current IP address.

While it is surely possible to write a program in python to FTP your
address somewhere, I think a little bit of shell would be easier.


#!/bin/sh

# make a temp file for the address
TNAME=3D`tempfile`

# extract the first IPv4 address of the interface 'eth0' and store it
# in the temp file
/sbin/ifconfig eth0 \
    | grep "inet addr" \
    | head -1 \
    | sed 's/.*inet addr:\([[:digit:].]\{7,15}\).*/\1/' \
    > $TNAME

# upload the file
echo "put $TNAME my_ip" | ftp theserver.com

# clean up
rm -f $TNAME


This requires that you put your username and password in ~/.netrc so
that the ftp program doesn't need to ask you for it.  Obviously change
the ftp line to use the right server and remote path, and change the
ifconfig line if you want to publish a different interface's address.

As neat as python is, try writing this program this quickly in it :-).

HTH,
-D

--=20

Trust in the Lord with all your heart and lean not on your own
understanding; in all your ways acknowledge Him, and He will make your
paths straight.
        Proverbs 3:5-6
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--azLHFNyN32YCQGCU
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjzr8EMACgkQO8l8XBKTpRR7AACdH7dNnTGzgN4m6hsueLPemy2J
3zcAoMuUln47zQWkbwYbxba4WeSZA4ux
=DT96
-----END PGP SIGNATURE-----

--azLHFNyN32YCQGCU--