On Mon, 14 May 2001, Alin Nastac wrote:

> Date: Mon, 14 May 2001 12:41:55 +0300 (EEST)
> From: Alin Nastac <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: [rlug] Re: netstat
>
>
> De aceeasi problema m-am izbit si eu. Din cite am vazut, nu exista un
> astfel de program. Informatia pe care o vrei tu se gaseste in
> /proc/net/ip_conntrack.
>
> Eu am facut un program in C care interpreteaza mai sus amintitul fisier.
> Problema e ca iti trebuie un xterm pentru a vedea informatia asta intr-un
> mod cit de cit lizibil (vreo 120 de coloane :)).
[...]
:))
Imi facusem si eu unul asemanator, in TCL :
nu afisaza chiar tot, unele cimpuri am banuit ce ar fi, dar nu m-am
cufundat asa tare in documentatii (surse):
L-am atasat (sper sa nu il stripuiasca listaru). Intre timp o sa il
compilez pe al tau, probabil ca afisaza mai multe informatii, si o sa il si folosesc :)

Banuiesc ca folosind netfilter (libiptc din iptables ?) se poate face mai
elegant.

____________________________________
Catalin Braica
[EMAIL PROTECTED]
Tel: 409-452-4161  Work: 405-141-3496
http://www.edulib.ro/~catalin/




-- Attached file included as plaintext by Listar --
-- File: conntrack.tcl

#!/usr/bin/tclsh


proc findHost {addr} {
        if {$addr == "127.0.0.1"} {
                return localhost;
        }
        # Try in /etc/hosts first.
        set fid [open "|./localhost $addr" r];
        set niceAddr [gets $fid]
        close $fid
        if {$niceAddr != ""} {
                return $niceAddr;
        }
        
        set err [catch {exec -- host $addr >tmp.ok}]
        set fid [open tmp.ok r]
        set file [read $fid]
        close $fid
        if {([string first "not found" $file] == -1) && ([string length $file] > 
[string length $addr])} {
                return [lindex [lindex [split $file \n] 0] end]
        }
        return $addr
}

set TIME_FORMAT "%M:%S"
set numericAddresses 0

if {[lsearch -exact $argv "-n"] != -1} {
        set numericAddresses 1
        set argv [lreplace $argv [lsearch -exact $argv "-n"] [lsearch -exact $argv 
"-n"]]
}

set activeTime [lindex $argv 0]
if {$activeTime == ""} {
        set activeTime 30
}

set fid [open /proc/net/ip_conntrack r]
set connections [split [read $fid] \n]
set connections [lrange $connections 0 [expr [llength $connections] -2]]
close $fid

foreach conn $connections {
        set tmpTtl 0
        catch {set tmpTtl [expr 432000 - [lindex $conn 2]]}
        if {$tmpTtl <= $activeTime} {
                set proto [lindex $conn 0]
                set ttl [clock format $tmpTtl -format $TIME_FORMAT]
                if {$proto == "udp"} {
                        set state "           "
                        set src [lindex [split [lindex $conn 3] =] 1]
                        set dst [lindex [split [lindex $conn 4] =] 1]
                        set sport [lindex [split [lindex $conn 5] =] 1]
                        set dport [lindex [split [lindex $conn 6] =] 1]
                } else {
                        set state [lindex $conn 3]
                        set src [lindex [split [lindex $conn 4] =] 1]
                        set dst [lindex [split [lindex $conn 5] =] 1]
                        set sport [lindex [split [lindex $conn 6] =] 1]
                        set dport [lindex [split [lindex $conn 7] =] 1]
                }
                set niceSrc $src
                set niceDst $dst
                if {!$numericAddresses} {
                        set niceSrc [findHost $src]
                        set niceDst [findHost $dst]
                }
                puts "[lindex $conn 2]\t$proto\t$ttl\t$state\t[format %-20s 
$niceSrc:$sport]\t=> $niceDst:$dport"
        }
        
}

-- Attached file included as plaintext by Listar --
-- File: localhost

#!/bin/bash
grep $1 /etc/hosts|awk '{print $3}'
-- Attached file included as plaintext by Listar --
-- File: c

#!/bin/bash
while :; do ./conntrack.tcl 60 | sort +1 > zzz; clear; cat zzz; sleep 1; done
---
Send e-mail to '[EMAIL PROTECTED]' with 'unsubscribe rlug' to 
unsubscribe from this list.

Raspunde prin e-mail lui