home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Shareware / Comunicatii / nat32 / script / UPDATE.TCL < prev    next >
Text File  |  2005-04-15  |  2KB  |  82 lines

  1. #!tcl
  2.  
  3. #
  4. # Update the IP.HTM file at NAT32.COM
  5. #
  6. # Usage: update usercode password
  7. #
  8.  
  9. # Check args
  10.  
  11. if {$argc != 2} {
  12.     error "Usage: update usercode password"
  13. }
  14.  
  15. # Get usercode and password
  16.  
  17. set usercode [lindex $argv 0]
  18. set password [lindex $argv 1]
  19.  
  20. # Compute the current IP address
  21.  
  22. set ip [exec url http://nat32.com/php/myip.php]
  23.  
  24. # Check result
  25.  
  26. set result [string first "ERROR" "$ip"]
  27. if {$result != "-1"} {
  28.     error $ip
  29. }
  30. set result [string first "404" "$ip"]
  31. if {$result != "-1"} {
  32.     error "ERROR: file myip.php not found"
  33. }
  34.  
  35. # We have the current IP
  36.  
  37. echo Current IP: $ip
  38.  
  39. # Fetch the ip.htm file
  40.  
  41. set response [exec ftp "get /public_html/ip.htm ip.htm nat32.com $usercode $password"]
  42.  
  43. set result [string first "ERROR" "$response"]
  44. if {$result != "-1"} {
  45.     error "ERROR: file ip.htm not found"
  46. }
  47.  
  48. echo File ip.htm downloaded
  49.  
  50. # Open files
  51.  
  52. set f_in  [open "ip.htm" r]
  53. set f_out [open "update.tmp" w]
  54.  
  55. # Generate a regular expression for an IP address string
  56.  
  57. set exp {[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:}
  58.  
  59. set modified 0
  60.  
  61. # Replace all IP addresses in the file
  62.  
  63. while {[gets $f_in line] >= 0} {
  64.     if {[regsub $exp $line "$ip:" nline]} {
  65.             puts $f_out $nline nonewline
  66.             if {$line != $nline} {
  67.                 set modified 1
  68.             }
  69.     } else {
  70.         puts $f_out $line nonewline
  71.     }
  72. }
  73. close $f_in
  74. close $f_out
  75.  
  76. if {$modified == 1} {
  77.     echo "Updating..."
  78.     set response [exec ftp "put update.tmp /public_html/ip.htm nat32.com $usercode $password"]
  79.     error Done $response
  80. }
  81. echo "File ip.htm is OK"
  82.