################################################################ # proc readFileAsList {fileName}-- # read in a file and convert it to a list delimited by newlines # Arguments # fileName Name of the file to read # # Results # no side effects # proc readFileAsList {fileName} { set if [open $fileName r] set d [read $if] close $if return [split $d \n] } source keyedListLibByReference.tcl set inputFile [open "IP2Name.txt" r] set data [read $inputFile] set IPName [split $data] proc getNameFromIP {address} { global IPName return [getValue $IPName $address] } set lst [readFileAsList practice.txt] set inputs {} set outputs {} set lines 0 foreach line $lst { lassign $line time in out localIP arrow remoteIP service if {$in ne ""} { set id $localIP~[getNameFromIP $remoteIP] # Retrieve the current total for this IP address set inTot [getValue $inputs $id] # If the total is an empty string, this IP address has not # been added to the list. Set the inTot variable to 0 (no bytes # so far) and append this IP address and value to the list # of inputs if {$inTot eq ""} { set inTot 0 appendKeyedPair inputs $id $inTot } set inTot [expr {$in + $inTot}] replaceValue inputs $id $inTot # Retrieve the current total for this IP address set outTot [getValue $outputs $id] # If the total is an empty string, this IP address has not # been added to the list. Set the outTot variable to 0 (no bytes # so far) and append this IP address and value to the list # of outputs if {$outTot eq ""} { set outTot 0 appendKeyedPair outputs $id $outTot } set outTot [expr {$out + $outTot}] replaceValue outputs $id $outTot } incr lines } foreach {id in} $inputs { set out [getValue $outputs $id] lassign [split $id ~] local remote puts "$local <-> $remote: IN: $in OUT: $out" }