3
# Copyright (C) 2001 Luca Deri <deri@ntop.org>
8
# LWP module can be downloaded from www.cpan.org
20
$passwdFile = $ENV{HOME}."/.ntopasswd";
23
##############################
26
for($i=0; $i<10; $i++) {
28
print $i."\t".$ARGV[$i]."\n";
35
###############################
37
if($ARGV[0] =~ /attach/) { attach(); }
38
elsif($ARGV[0] =~ /lsdev/) { lsdev(); }
39
elsif($ARGV[0] =~ /devinfo/) { devinfo(); }
40
elsif($ARGV[0] =~ /lshost/) { lshost(); }
41
elsif($ARGV[0] =~ /hostinfo/) { hostinfo(); }
42
elsif($ARGV[0] =~ /arp/) { arp(); }
43
elsif($ARGV[0] =~ /nbt/) { nbt(); }
47
##############################
50
# attach [user:pw@]host:port
52
if($ENV{NTOP_ROOT} eq "") {
53
print "ERROR: NTOP_ROOT is empty. Set it to user\@ntopHost:ntopPort\n\n";
57
if($ENV{NTOP_ROOT} =~ /(\S*)@(\S*):(\d*)/) {
63
print "user: $ntopUser\n";
64
print "host: $ntopHost\n";
65
print "port: $ntopPort\n";
68
if(($1 eq "") || ($2 eq "") || ($3 eq "")) {
69
print "ERROR: NTOP_ROOT is not properly defined. Set it to user\@ntopHost:ntopPort\n\n";
74
$ntopPwd = <STDIN>; chop($ntopPwd);
76
if($debug) { print "Password: '".$ntopPwd."'\n"; }
78
$URL = "http://$ntopUser:$ntopPwd\@".$ntopHost.":".$ntopPort."/";
80
if($debug) { print "URL: '".$URL."'\n"; }
85
print "ERROR: unable to connect to ntop. Please check host:port/user/pw\n";
88
print "User $ntopUser successfully connected to $ntopHost:$ntopPort\n";
91
umask((umask() & 077) | 077); # -rw-------
93
if(open(OUT, "> ".$passwdFile)) {
94
print OUT "http://$ntopUser:$ntopPwd\@".$ntopHost.":".$ntopPort."/\n";
97
print "ERROR: unable to create/update file $passwdFile\n";
105
##############################
110
$content = get($homeNtopURL."dumpTrafficData.html?language=perl&filter=ifAddr");
112
if($debug) { print "Received: $content\n"; }
115
print "ERROR: unable to talk with ntop.\n";
118
%hash = eval($content);
120
while (($key, $value) = each %hash) {
126
##############################
132
while (($key, $value) = each %elems) {
133
if($value =~ /^HASH/) {
134
while (($key1, $value1) = each %$value) {
135
if($value1 =~ /^HASH/) {
136
while (($key2, $value2) = each %$value1) {
137
$unbundled[$index][0] = $key.":".$key.":".$key2;
138
$unbundled[$index][1] = $value2;
142
$unbundled[$index][0] = $key.":".$key1;
143
$unbundled[$index][1] = $value1;
148
$unbundled[$index][0] = $key;
149
$unbundled[$index][1]= $value;
157
##############################
160
if($ARGV[1] eq "") { usage(); }
164
$content = get($homeNtopURL."dumpTrafficData.html?language=perl&key=$ARGV[1]");
166
if($debug) { print "Received: $content\n"; }
169
print "ERROR: unable to talk with ntop.\n";
172
%hash = eval($content);
174
if(!$hash{$ARGV[1]}) {
175
print "ERROR: unknown device $ARGV[1].\n";
179
$elems = $hash{$ARGV[1]};
181
@allelems = unbundle(%elems);
183
foreach $i (0 .. $#allelems) {
184
printf("%-30s\t%s\n", $allelems[$i][0], $allelems[$i][1]);
189
##############################
194
$content = get($homeNtopURL."dumpData.html?language=perl&filter=ethAddressString");
196
if($debug) { print "Received: $content\n"; }
199
print "ERROR: unable to talk with ntop.\n";
202
%hash = eval($content);
204
while (($key, $value) = each %hash) {
210
##############################
213
if($ARGV[1] eq "") { usage(); }
217
$content = get($homeNtopURL."dumpData.html?language=perl&key=$ARGV[1]");
219
if($debug) { print "Received: $content\n"; }
222
print "ERROR: unable to talk with ntop.\n";
225
%hash = eval($content);
227
if(!$hash{$ARGV[1]}) {
228
print "ERROR: unknown device $ARGV[1].\n";
232
$elems = $hash{$ARGV[1]};
234
@allelems = unbundle(%elems);
236
foreach $i (0 .. $#allelems) {
237
printf("%-30s\t%s\n", $allelems[$i][0], $allelems[$i][1]);
242
##############################
247
$content = get($homeNtopURL."dumpData.html?language=perl&filter=ethAddressString");
249
if($debug) { print "Received: $content\n"; }
252
print "ERROR: unable to talk with ntop.\n";
255
%hash = eval($content);
257
while (($key, $dummy) = each %hash) {
258
my($macAddress) = $hash{$key}{ethAddressString};
261
&& ($macAddress ne "")
262
&& (!($key =~ /:/))) {
263
printf("%-20s\t%-20s\n", $key, $macAddress);
271
##############################
276
$content = get($homeNtopURL."dumpData.html?language=perl&filter=nbHostName");
278
if($debug) { print "Received: $content\n"; }
281
print "ERROR: unable to talk with ntop.\n";
284
%hash = eval($content);
286
while (($key, $dummy) = each %hash) {
287
my($nbHostName) = $hash{$key}{nbHostName};
289
if(($key ne "") && ($nbHostName ne "")) {
290
printf("%-20s\t%-20s\n", $key, $nbHostName);
297
##############################
300
if(open(IN, $passwdFile)) {
304
if($homeNtopURL eq "") {
305
print "ERROR: problems while reading $passwdFile. Did you attach to a running ntop?\n";
309
print "ERROR: unable to read file $passwdFile. Did you attach to a running ntop?\n";
315
##############################
320
nClient <command> [ <parameters> ]
323
attach attach to a running ntop
324
lsdev show ntop available network devices
325
devinfo <device> show info about the specified device
326
lshost <host> show ntop's known host
327
hostinfo show info about the specified host
328
arp show ntop's ARP table
329
nbt show ntop's NetBIOS hosts
333
1) start a copy of ntop at ntopHost:ntopPort
334
2) Set the environment variable NTOP_ROOT to
335
user\@ntopHost:ntopPort
337
For instance (on tcsh):
338
setenv NTOP_ROOT luca\@dummy.ntop.org:3000
340
4) nClient <insert your command here>
343
======================================
345
(C) 2001 - Luca Deri <deri\@ntop.org>\n";