perl en brazilfw [INACTIVE]

Here we discuss compilation and how to build an addon for BFW.

perl en brazilfw

Mensagempor nachazo » Qui Set 17, 2009 10:13 pm

Chicos estoy usando perl como mediador mediante telnet de demonios.

En este caso estoy intentando controlar a mldonkey mediante perl...

Les dejo cortesia de ANGEL un script que permite tomar variables del sistema de brazilfw y ponerlas a nuestro servicio en nuestro script perl...

Código: Selecionar todos
#!/usr/local/bin/perl
#

use Config::General; #modulo
##############---- Lectura de variables coyote.conf---##########################

my $configfile = new Config::General("/etc/coyote/coyote.conf"); #ruta de fichero a leer
my %config = $configfile->getall;

$ip_local = $config{LOCAL_IPADDR}; #busco LOCAL_IPADDR
$ip_local =~s/\'//g; #LE QUITO LOS ACENTOS

print "$ip_local\n"; #MUESTRO EN PANTALLA RESULTADO


Saludos.
nachazo
 

Re: perl en brazilfw

Mensagempor pablino76 » Sex Abr 30, 2010 2:11 pm

Bueeenoo joya me re garpo el script ese, era justamente lo que estaba craneando
Muchos thank's angelito.
hacete unos par de rescates mas

Código: Selecionar todos
#!/usr/bin/perl -w
#
# Maps the IP addresses on your local Ethernet to their ARP equivalents
#
# REQUIRES: Being run by any user authorized to run ping, arp and ifconfig
use strict;

use vars qw($ifconfigCmd $findCmd $arpCmd $interactive %done);

my ($ip,$mask,$class,$filename);

# ---------configuration area--------
# Path to the ifconfig binary

$ifconfigCmd = '/sbin/ifconfig';

# Command to run to find a host
# (a simple ping will do, just take care not to
# execute an eternal ping)
#
# Put %ip% where the IP should be given.

$findCmd = '/bin/ping -c 1 %ip%';

# Path to the arp binary

$arpCmd = '/sbin/arp';

# filename for output. If the file already exists, it

# will be checked, in order not to repeat the whole

# process.

# If left empty, output will go to STDOUT.

if ($ARGV[1]) {

$filename=$ARGV[1];

} else {

$filename = 'arpmap.txt';

}

# -----end of configuration area-----

#

# Run in interactive mode if called with no arguments

$interactive = ($#ARGV==-1);

($ip,$mask) = &findIp();

$class=&checkMask($mask);

&openFile($filename) if (defined $filename && $filename ne '');

$|=1;

&getArp($ip,$class);

close(OUT) if (defined $filename && $filename ne '');

exit 0;

sub openFile {

my ($filename);

$filename=$_[0];

&readFile($filename) if (-f $filename);

open (OUT,">>$filename") or die "Could not open $filename for output";

select(OUT);

}

sub readFile {

my ($filename,@in,$line,$ip,$mac);

$filename=$_[0];

open (IN,$filename) or die "Could not open $filename for input";

@in=<IN>;

close (IN);

while ($line=shift(@in)) {

($ip,$mac) = split(' - ',$line);

$done{$ip}=$mac;

}

}

sub findIp {

my ($line,@ifconfig,%interfaces,$int,$ip,$mask);

@ifconfig=`$ifconfigCmd`;

while ($line = shift(@ifconfig)) {

chomp $line;

if ($line =~ s/^([\w\d\:]+).*/$1/ && $line ne 'lo') {

$interfaces{$line} = shift(@ifconfig);

chomp($interfaces{$line});

}

}

if ($interactive) {

$int='';

while (not defined $interfaces{$int}) {

print "\nThe following interfaces were found on your system:\n";

print join ("\n ",keys(%interfaces));

print "\nWhich interface do you want to map? ";

$int = <STDIN>;

chomp ($int);

}

} else {

if (defined $interfaces{$ARGV[0]}) {

$int = $ARGV[0];

} else {

print "\nInterface $ARGV[0] not found\n\n";

exit 0

}

}

$ip = $mask = $interfaces{$int};

$ip =~ s/^.*inet addr:([\d\.]+).*/$1/;

$mask =~ s/^.*Mask:([\d\.]+).*/$1/;

return ($ip,$mask);

}

sub checkMask {

my ($mask,@mask,$class);

$mask=$_[0];

@mask = split(/./,$mask);

if ($mask eq '255.255.255.0') {

$class=24;

} elsif ($mask eq '255.255.0.0') {

$class=16;

} elsif ($mask eq '255.0.0.0' || $mask eq '0.0.0.0') {

print "Your network is too large - Stay out of troubles, don't try to map it.\n";

exit 0;

} elsif ($mask eq '255.255.255.255') {

print "This is a point-to-point network or something weird.\n";

print "I'd better cowardly stay away from it...";

exit 0;

} else {

print "Sorry, arpmap does not handle subclasses yet.\n";

exit 0;

}

return $class;

}

sub getArp {

my ($myip,$class,$ip,$oct3,$oct4);

$myip = $_[0];

$class = $_[1];

$ip = $myip;

# $class must be either 16 or 24

if ($class == 24) {

$ip =~ s/^(\d+\.\d+\.\d+\.).*/$1/;

for ($oct4=1;$oct4<255;$oct4++) {

&getIp($ip.$oct4);

}

} elsif ($class == 16) {

$ip =~ s/^(\d+\.\d+\.).*/$1/;

for ($oct3=1;$oct3<255;$oct3++) {

for ($oct4=0;$oct4<=255;$oct4++) {

&getIp($ip.$oct3.$oct4);

}

}

} else {

die "I was waiting for a 16 or a 24 and got a $class!";

}

}

sub getIp {

my ($ip,$command,@arp,@arp2,$arp,$line);

$ip=$_[0];

return if (defined $done{$ip});

$command = $findCmd;

$command =~ s/\%ip\%/$ip/;

system("$command > /dev/null");

@arp=`$arpCmd $ip`;

foreach $line (@arp) {

chomp $line;

# Go to next line if this one is the header

next if ($line =~ /Address.*HWtype/ || $line =~ /incomplete/);

@arp2=split(/\s+/,$line);

$arp = $arp2[2];

print "$ip - $arp\n" if ($arp !~ /--/);

}

}


Aguante Paganini.
pablino76
 

Re: perl en brazilfw

Mensagempor M客¡NhØ §åMµ®å¡ » Sex Abr 30, 2010 2:15 pm

nachazo escreveu:Chicos estoy usando perl como mediador mediante telnet de demonios.

En este caso estoy intentando controlar a mldonkey mediante perl...

Les dejo cortesia de ANGEL un script que permite tomar variables del sistema de brazilfw y ponerlas a nuestro servicio en nuestro script perl...

Código: Selecionar todos
#!/usr/local/bin/perl
#

use Config::General; #modulo
##############---- Lectura de variables coyote.conf---##########################

my $configfile = new Config::General("/etc/coyote/coyote.conf"); #ruta de fichero a leer
my %config = $configfile->getall;

$ip_local = $config{LOCAL_IPADDR}; #busco LOCAL_IPADDR
$ip_local =~s/\'//g; #LE QUITO LOS ACENTOS

print "$ip_local\n"; #MUESTRO EN PANTALLA RESULTADO


Saludos.

:aplause: :aplause: :aplause: :aplause:
Para nós que utilizamos alguns scripts baseados em Perl, é de muita ajuda essa informação.

Obrigado por compartilhar conosco! :o!

Gracias, hermano! :o!
Utilize a busca do fórum! Ela é sua amiga!
Não dou suporte via MP ou MSN para ninguém. Por favor, não insista. (Para que existe o fórum?)
É novo aqui? É "antigo" e mesmo assim está perdido?
Então leia:
Avatar do usuário
M客¡NhØ §åMµ®å¡
BFW Developer
BFW WebServer
BFW Beneméritos
BFW Add-on Developer
BFW Moderator
BFW Manager
 
Mensagens: 4111
Registrado em: Qua Abr 08, 2009 11:06 am
Localização: Rio de Janeiro
BrazilFW Box: Máquina Física
CPU: AMD Athlon(tm) II X2 215 Processor
Memória: 1 GiB / Link 50 MB
BFW 3.0.262 64 bits.
Serviços Ativos: DNS, DHCP
Addons: Samba, Pure-FTPd (no certified), BFW WebServer (no certified)


Voltar para Add-On Factory

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 16 visitantes

cron