Re: Getting my WAN IP address from ppp0
On Tuesday, January 6, 2004, at 09:57 PM, Stephan Hochhaus [EMAIL PROTECTED] wrote: Is there a way to read out my WAN IP address in Mac OS X (maybe extract it from a logfile) and write it to a file? FWIW, I use http://checkip.dyndns.org/ for this purpose; its output is easy to parse. I do it with a small shell script: #!/bin/sh # hostip - print WAN-side IP address wget -O - http://checkip.dyndns.org/ 2/dev/null | sed '1s/[^0-9.]//g' I am sorry if this is too basic a question, I just started my long journey to become a Perl monger. Don't worry; basic questions are fine. In fact, I like to see basic questions because they're much easier to answer. :-) HTH, Paul. -- Paul Hoffman :: Taubman Medical Library :: Univ. of Michigan [EMAIL PROTECTED] :: [EMAIL PROTECTED] :: http://www.nkuitse.com/
Re: Getting my WAN IP address from ppp0
Hi Zach, Well, this almost works for me. #!perl my $ifconfig = `ifconfig`; # the ifconfig command gives the current network information $ifconfig =~ /inet (\d+\.\d+\.\d+\.\d+)/; # extract the ip address with a regular expression This does extract my IP address, but the one for the loopback device lo0. The ifconfig output looks like this: lo0: flags=8049UP,LOOPBACK,RUNNING,MULTICAST mtu 16384 inet6 ::1 prefixlen 128 inet6 fe80::1 prefixlen 64 scopeid 0x1 inet 127.0.0.1 netmask 0xff00 gif0: flags=8010POINTOPOINT,MULTICAST mtu 1280 stf0: flags=0 mtu 1280 en0: flags=8863UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST mtu 1500 tunnel inet -- ether 00:30:65:ef:a8:f0 media: autoselect (10baseT/UTP half-duplex) status: active supported media: none autoselect 10baseT/UTP half-duplex 10baseT/UTP full-duplex 10baseT/UTP full-duplex,hw-loopback 100baseTX half-duplex 100baseTX full-duplex 100baseTX full-duplex,hw-loopback 1000baseTX full-duplex 1000baseTX full-duplex,hw-loopback 1000baseTX full-duplex,flow-control 1000baseTX full-duplex,flow-control,hw-loopback fw0: flags=8822BROADCAST,SMART,SIMPLEX,MULTICAST mtu 2030 tunnel inet -- lladdr 00:30:65:ff:fe:ef:a8:f0 media: autoselect full-duplex status: inactive supported media: autoselect full-duplex ppp0: flags=8051UP,POINTOPOINT,RUNNING,MULTICAST mtu 1492 inet 212.212.2.212 -- 212.128.128.12 netmask 0xff00 Now I would like to start reading the output from just the last line. Is there anyway to start reading it from the end to the beginning and stop once the inet line is found? my $ip = $1; what's $1? Why is that needed? I suppose it is an internal perl variable like $_, right? The reason I don't want to use dyndns is, that I don't completely trust it and I might sometimes not need it for more than 30 days which leads to expiration of the address if I read things correctly. Thanks a lot for your help. Stephan
Re: Getting my WAN IP address from ppp0
Hi Zach, Well, this almost works for me. #!perl my $ifconfig = `ifconfig`; # the ifconfig command gives the current network information $ifconfig =~ /inet (\d+\.\d+\.\d+\.\d+)/; # extract the ip address with a regular expression This does extract my IP address, but the one for the loopback device lo0. The ifconfig output looks like this: lo0: flags=8049UP,LOOPBACK,RUNNING,MULTICAST mtu 16384 inet6 ::1 prefixlen 128 inet6 fe80::1 prefixlen 64 scopeid 0x1 inet 127.0.0.1 netmask 0xff00 gif0: flags=8010POINTOPOINT,MULTICAST mtu 1280 stf0: flags=0 mtu 1280 en0: flags=8863UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST mtu 1500 tunnel inet -- ether 00:30:65:ef:a8:f0 media: autoselect (10baseT/UTP half-duplex) status: active supported media: none autoselect 10baseT/UTP half-duplex 10baseT/UTP full-duplex 10baseT/UTP full-duplex,hw-loopback 100baseTX half-duplex 100baseTX full-duplex 100baseTX full-duplex,hw-loopback 1000baseTX full-duplex 1000baseTX full-duplex,hw-loopback 1000baseTX full-duplex,flow-control 1000baseTX full-duplex,flow-control,hw-loopback fw0: flags=8822BROADCAST,SMART,SIMPLEX,MULTICAST mtu 2030 tunnel inet -- lladdr 00:30:65:ff:fe:ef:a8:f0 media: autoselect full-duplex status: inactive supported media: autoselect full-duplex ppp0: flags=8051UP,POINTOPOINT,RUNNING,MULTICAST mtu 1492 inet 212.212.2.212 -- 212.128.128.12 netmask 0xff00 If you want the ip address of PPPoE connection, change the first line of the script to my $ifconfig = `ifconfig ppp0`; HTH, Rick Smith
Solution: Getting my WAN IP address from ppp0 and upload via ftp
Hey Zach, Rick and everyone who helped me on this: I just finished a very simple script that reads out my IP-address from the ppp0 device, creates a small HTML file and uploads it to my webhoster so i can access my g4 from anywhere in the world. The script is the patchwork of a beginner, so any advice on making it nicer is greatly appreciated. It is run as a cronjob to assure the up-to-dateness of the IP. Anyway, here's the script: #!/usr/bin/perl use Net::FTP; #all the neccessary info for loggin into the ftp server my $hostname = 'myftpserver.com'; my $user ='username'; my $pass = 'password'; #where on the server should which file go? my $dir = '/public_html'; my $file = '/Users/Shared/g4server.html'; #read out my ip address my $ifconfig = `ifconfig ppp0`; # the ifconfig command gives the current network information $ifconfig =~ /inet (\d+\.\d+\.\d+\.\d+)/; # extract the ip address with a regular expression my $ip = $1; # write it to a html file open (OUTPUT,/Users/Shared/g4server.html); print OUTPUT HTMLHEADTITLEg4server address/TITLE/HEADBODY; print OUTPUT H1Access g4server.local/H1\n; print OUTPUT 'a href=http://'; print OUTPUT $ip; print OUTPUT Apache/abr /\n; print OUTPUT 'a href=https://'; print OUTPUT $ip; print OUTPUT :1Webmin/abr /\n; print OUTPUT /BODY/HTML; close (OUTPUT); #upload the html file $ftp = Net::FTP-new($hostname); $ftp-login($user, $pass); $ftp-cwd($dir); $ftp-put($file); $ftp-quit; Maybe it will brighten up some other beginners day :-) Stephan
Re: Solution: Getting my WAN IP address from ppp0 and upload via ftp
* Stephan Hochhaus [EMAIL PROTECTED] I just finished a very simple script that reads out my IP-address from the ppp0 device, creates a small HTML file and uploads it to my webhoster so i can access my g4 from anywhere in the world. The script is the patchwork of a beginner, so any advice on making it nicer is greatly appreciated. It is run as a cronjob to assure the up-to-dateness of the IP. Anyway, here's the script: #!/usr/bin/perl use strict; use warnings; use Net::FTP; #all the neccessary info for loggin into the ftp server my $hostname = 'myftpserver.com'; my $user ='username'; my $pass = 'password'; #where on the server should which file go? my $dir = '/public_html'; my $file = '/Users/Shared/g4server.html'; #read out my ip address my $ifconfig = `ifconfig ppp0`; # the ifconfig command gives the current network information $ifconfig =~ /inet (\d+\.\d+\.\d+\.\d+)/; # extract the ip address with a regular expression my $ip = $1; # no sense in writing no data if we did not get any... die error: could not parse address from ifconfig unless $ip; # write it to a html file open (OUTPUT,/Users/Shared/g4server.html); # you declare $file above, but do no use it here? # anyways, error checking is a must! open (OUTPUT, $file) or die error: could not write $file: $!\n; print OUTPUT HTMLHEADTITLEg4server address/TITLE/HEADBODY; print OUTPUT H1Access g4server.local/H1\n; print OUTPUT 'a href=http://'; print OUTPUT $ip; print OUTPUT Apache/abr /\n; print OUTPUT 'a href=https://'; print OUTPUT $ip; print OUTPUT :1Webmin/abr /\n; print OUTPUT /BODY/HTML; # a here document is much shorter, and cleaner: print OUTPUT HTMLSTUFF; HTMLHEADTITLEg4server address/TITLE/HEADBODY H1Access g4server.local/H1 pa href=http://$ip/;Apache/a/p pa href=https://$ip:1/;Webmin/a/p /body/html HTMLSTUFF close (OUTPUT); # when writing to a file, *always* check the status on close, as this is # when you figure out that the disk is full or something else went wrong # and have a chance to log the error or fallback... close OUTPUT or die error: problem closing $file: $!\n; #upload the html file $ftp = Net::FTP-new($hostname); $ftp-login($user, $pass); $ftp-cwd($dir); $ftp-put($file); $ftp-quit; There's probably error checking that can be done on the FTP calls, as well... Other improvements would be to write out the HTML file to a temporary file (see the File::Temp perl module), and doing a rename on that to the proper filename, but only if the files are different. This would allow you to skip uploading to FTP should nothing have changed, and reduce the chance that you hit the page when the file is being updated.
Getting my WAN IP address from ppp0
Hello out there, I know this has been asked before, and I have taken a look at at least one thousand websites, but I couldn't come up with a working solution as of yet. I want to upload a textfile to my website, that contains the IP of my Mac at home (which is assigned dynamically since it connects via DSL using PPPoE). I tried various ways to get the IP, I even tried the tricky solution that can be found around the net, to parse a website that basically lists the %ENV variables. Unfortunately to no success. Is there a way to read out my WAN IP address in Mac OS X (maybe extract it from a logfile) and write it to a file? I am sorry if this is too basic a question, I just started my long journey to become a Perl monger. Enjoy the new year, Stephan
Re: Getting my WAN IP address from ppp0
There are a couple of quick and dirty ways to do this. Here's one solution: #!perl my $ifconfig = `ifconfig`; # the ifconfig command gives the current network information $ifconfig =~ /inet (\d+\.\d+\.\d+\.\d+)/; # extract the ip address with a regular expression my $ip = $1; # write it to a text file open (OUTPUT,/path/to/file.txt); print OUTPUT $ip; close (OUTPUT); From here you could handle special cases such as no ip address or ipv6. The better question however is why you would want to do this when there are free systems like dyndns (dyndns.org) that let you have your own yourname.dyndns.org domain that points to your dynamic IP. Dyndns has mac-compatible client software as well (http://www.dyndns.org/services/dyndns/clients.html) and is free. Zach On Jan 5, 2004, at 1:51 PM, Stephan Hochhaus wrote: Hello out there, I know this has been asked before, and I have taken a look at at least one thousand websites, but I couldn't come up with a working solution as of yet. I want to upload a textfile to my website, that contains the IP of my Mac at home (which is assigned dynamically since it connects via DSL using PPPoE). I tried various ways to get the IP, I even tried the tricky solution that can be found around the net, to parse a website that basically lists the %ENV variables. Unfortunately to no success. Is there a way to read out my WAN IP address in Mac OS X (maybe extract it from a logfile) and write it to a file? I am sorry if this is too basic a question, I just started my long journey to become a Perl monger. Enjoy the new year, Stephan