5752079 [rkeene@sledge /home/rkeene/devel/old/tcl]$ cat -n dyndns-client.tcl
   1: #!/usr/bin/tclsh
   2: set HOST "208.159.161.157"
   3: set PORT 32766
   4: set FILE /etc/dyndns.conf
   5: set DYNHOST dyn.n-f-d.com
   6: 
   7: 
   8: proc putsock {sock text} {
   9:   puts $sock $text
  10:   flush $sock
  11: }
  12: 
  13: catch {
  14:   set fileId [open $FILE r]
  15: }
  16: if {![info exists fileId]} {
  17:   puts "Unable to open $FILE"
  18:   exit
  19: }
  20: 
  21: gets $fileId ln
  22: set username [lindex $ln 0]
  23: set password [lindex $ln 1]
  24: if {[lindex $argv 0]!=""} {
  25:   set ip [split [exec /sbin/ifconfig] \n]
  26:   set NextLine 0
  27:   foreach line $ip {
  28:     if {$NextLine} {
  29:       set ip [lindex [split [lindex $line 1] :] 1]
  30:       break
  31:     }
  32:     if {[string range [lindex $line 0] 0 3]==[lindex $argv 0]} { set NextLine 1 }
  33:   }
  34: } else {
  35:   set ip ""
  36: }
  37: 
  38: catch {
  39:   set sockId [socket $HOST $PORT]
  40: }
  41: if {![info exists sockId]} {
  42:   puts "Unable to create connection to $HOST $PORT."
  43:   exit
  44: }
  45: gets $sockId ln
  46: if {[lindex $ln 0]!="220"} { puts "Failed"; exit }
  47: putsock $sockId "USER $username"
  48: gets $sockId ln
  49: if {[lindex $ln 0]!="331"} { puts "Failed"; exit }
  50: putsock $sockId "PASS $password"
  51: gets $sockId ln
  52: if {[lindex $ln 0]!="230"} { puts "Failed"; exit }
  53: putsock $sockId "SETI $ip"
  54: gets $sockId ln
  55: if {[lindex $ln 0]!="220"} { puts "Failed"; exit }
  56: puts "Updated.  $username\.$DYNHOST set to $ip"
  57: putsock $sockId "QUIT"
  58: gets $sockId ln
  59: close $sockId
5752080 [rkeene@sledge /home/rkeene/devel/old/tcl]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2001-04-29 23:59:52