home *** CD-ROM | disk | FTP | other *** search
- #!tcl
-
- #
- # Update the IP.HTM file at NAT32.COM
- #
- # Usage: update usercode password
- #
-
- # Check args
-
- if {$argc != 2} {
- error "Usage: update usercode password"
- }
-
- # Get usercode and password
-
- set usercode [lindex $argv 0]
- set password [lindex $argv 1]
-
- # Compute the current IP address
-
- set ip [exec url http://nat32.com/php/myip.php]
-
- # Check result
-
- set result [string first "ERROR" "$ip"]
- if {$result != "-1"} {
- error $ip
- }
- set result [string first "404" "$ip"]
- if {$result != "-1"} {
- error "ERROR: file myip.php not found"
- }
-
- # We have the current IP
-
- echo Current IP: $ip
-
- # Fetch the ip.htm file
-
- set response [exec ftp "get /public_html/ip.htm ip.htm nat32.com $usercode $password"]
-
- set result [string first "ERROR" "$response"]
- if {$result != "-1"} {
- error "ERROR: file ip.htm not found"
- }
-
- echo File ip.htm downloaded
-
- # Open files
-
- set f_in [open "ip.htm" r]
- set f_out [open "update.tmp" w]
-
- # Generate a regular expression for an IP address string
-
- set exp {[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:}
-
- set modified 0
-
- # Replace all IP addresses in the file
-
- while {[gets $f_in line] >= 0} {
- if {[regsub $exp $line "$ip:" nline]} {
- puts $f_out $nline nonewline
- if {$line != $nline} {
- set modified 1
- }
- } else {
- puts $f_out $line nonewline
- }
- }
- close $f_in
- close $f_out
-
- if {$modified == 1} {
- echo "Updating..."
- set response [exec ftp "put update.tmp /public_html/ip.htm nat32.com $usercode $password"]
- error Done $response
- }
- echo "File ip.htm is OK"
-