Foros del Web » Administración de Sistemas » Unix / Linux »

[SOLUCIONADO] perl /sbin/iwlist scan 2>&1

Estas en el tema de perl /sbin/iwlist scan 2>&1 en el foro de Unix / Linux en Foros del Web. Hola que tal a todos. estoy buscando un codigo que extraiga estos datos mediante este comando "/sbin/iwlist scan 2>&1" Código: mon0 Interface doesn't support scanning ...
  #1 (permalink)  
Antiguo 28/07/2014, 15:22
Avatar de Melecio  
Fecha de Ingreso: julio-2011
Ubicación: Coahuila
Mensajes: 320
Antigüedad: 13 años, 4 meses
Puntos: 8
perl /sbin/iwlist scan 2>&1

Hola que tal a todos.


estoy buscando un codigo que extraiga estos datos mediante este comando "/sbin/iwlist scan 2>&1"


Código:
mon0      Interface doesn't support scanning : Operation not supported

eth0      Interface doesn't support scanning.

lo        Interface doesn't support scanning.

wlan0     Scan completed :
          Cell 01 - Address: A1:5F:E2:60:D8:B1
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-19 dBm
                    Encryption key:on
                    ESSID:"NETGEAR"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                              24 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=00000002042e84bc
                    Extra: Last beacon: 36ms ago
                    IE: Unknown: 00074E455447454152
                    IE: Unknown: 010882840B162430486C
                    IE: Unknown: 030106
                    IE: Unknown: 2A0100
                    IE: Unknown: 2F0100
                    IE: Unknown: 32040C121860
                    IE: Unknown: DD050050F20500
                    IE: Unknown: DD7F0050F204104A00011010440001021041000100103B000103104700109E8E3168C515D33BDF09220FF88526BE1021000D4E4554474541522C20496E632E10230009574752363134763130102400095747523631347631301042000538333235381054000800060050F204000110110009574752363134763130100800020084
                    IE: Unknown: DD090010180201F0050000
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
          Cell 02 - Address: 1C:7E:3C:CC:A4:B5
                    Channel:2
                    Frequency:2.417 GHz (Channel 2)
                    Quality=40/70  Signal level=-70 dBm
                    Encryption key:on
                    ESSID:"ZARA"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000002cc8050d80
                    Extra: Last beacon: 3104ms ago
                    IE: Unknown: 00085A415241474F5A41
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030102
                    IE: Unknown: 050400010000
                    IE: Unknown: 2A0100
                    IE: Unknown: 32043048606C
                    IE: Unknown: DD180050F2020101820003A4000027A4000042435E0062322F00
                    IE: Unknown: DD1E00904C334C101BFF00000000000000000000000000000000000000000000
                    IE: Unknown: 2D1A4C101BFF00000000000000000000000000000000000000000000
                    IE: Unknown: DD1A00904C3402001B00000000000000000000000000000000000000
                    IE: Unknown: 3D1602001B00000000000000000000000000000000000000
                    IE: Unknown: DD0900037F01010000FF7F
                    IE: Unknown: DD0A00037F04010002004000
                    IE: Unknown: DD260050F204104A0001101044000102104900140024E26002000101600000020001600100020001
                    IE: Unknown: DD050050F20500
          Cell 03 - Address: 00:D5:75:41:71:4A
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=59/70  Signal level=-51 dBm
                    Encryption key:on
                    ESSID:"RODE"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                              24 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=0000002cc9d21ed4
                    Extra: Last beacon: 36ms ago
                    IE: Unknown: 0009494D504F2D4558504F
                    IE: Unknown: 010882848B962430486C
                    IE: Unknown: 030106
                    IE: Unknown: 2A0104
                    IE: Unknown: 2F0104
                    IE: Unknown: 32040C121860
                    IE: Unknown: DD7F0050F204104A0001101044000102103B00010310470010E1BBB2B46DFCC171F1E62F77679A8C9A102100074C696E6B73797310230006526F757465721024000857525435344753321042000C43555130314A3341363438321054000800060050F204000110110011576972656C6573732D4720526F75746572100800020084
                    IE: Unknown: DD090010180200F5000000
          Cell 04 - Address: 74:77:35:70:45:10
                    Channel:11
                    Frequency:2.462 GHz (Channel 11)
                    Quality=31/70  Signal level=-79 dBm
                    Encryption key:on
                    ESSID:"MTM"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                              24 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=0000001b7fb73183
                    Extra: Last beacon: 100ms ago
                    IE: Unknown: 00034D544D
                    IE: Unknown: 010882848B962430486C
                    IE: Unknown: 03010B
                    IE: Unknown: 050401020000
                    IE: Unknown: 2A0107
                    IE: Unknown: 2F0107
                    IE: Unknown: 32040C121860
                    IE: Unknown: DD270050F204104A00011010440001021047001041E7906779845DCE7D5762CD93C18018103C000103
                    IE: Unknown: DD050050F20500
                    IE: Unknown: DD09001018020BF02C0000
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00


tengo este codigo pero no me extrae el tipo de cifrado ni la mac addres

Código:
#!/usr/bin/perl

# {{{ use

use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
# }}}

system "clear";


my %opts;
getopts('doehi:p:n:s:', \%opts);
# {{{ usage

# }}}

use constant {
  USERNAME => 2,
  PASSWORD => 1,
};

# bitflags, 1 = password, 2 = username
my $authentication = 0;
my $encryption = undef;
my $essid = shift @ARGV;

# {{{ Network selection
if (not defined $essid) {
  my $interface = defined $opts{'i'} ? $opts{'i'} : 'wlan0';
  my @networks = ();
  my $ignoreNextGc = 0;
  my @scan = ();
  if (defined $opts{'s'}) {
    open my $h, $opts{'s'} or die "Failed to read scanfile: $!\n";
    @scan = <$h>;
    close $h;
  } else {
    @scan = `iwlist $interface scan`;
  }

 my $network = undef;
  foreach (@scan) {
    if (/Cell \d+ - Address: /) {
      push @networks, $network if defined $network and defined $network->{'essid'};

      $network = {
        'authentication' => 0,
        'encryption' => 0
      };
      $ignoreNextGc = 0;
    } elsif (/quality=(\d+)\/70/i) {
      $network->{'quality'} = 100 * $1/70;
      $network->{'quality'} = 100 if $1 > 70;
    } elsif (/ESSID:"(.+)"/) {
      $network->{'essid'} = $1;
    } elsif (/Encryption key:(on|off)/) {
      $network->{'authentication'} = $network->{'authentication'} | PASSWORD if $1 eq 'on';
    } elsif (/IE: WPA Version \d/) {
      # if for WPA+WPA2
      if ($network->{'encryption'}) {
        $ignoreNextGc = 1;
      } else {
        $network->{'encryption'} = 'WPA';
      }
    } elsif (/IE: IEEE 802.11i\/WPA2 Version \d/) {
      $network->{'encryption'} = 'WPA2' if $network->{'encryption'} !~ /WPA Enterprise/;
    } elsif (/Group Cipher : (.*)$/) {
    } elsif (/Authentication Suites \(\d+\) : 802\.1x/) {
    }
  }


push @networks, $network if defined $network and defined $network->{'essid'};


  if (@networks <= 1) {
    print "Very few networks were found, perhaps you should run this script as root?\n";
  }


  @networks = sort {$b->{'quality'} <=> $a->{'quality'}} @networks;
  sub quality {
    my $network = shift;
    return '+' if $network->{'quality'} >= 80;
    return '-' if $network->{'quality'} <= 30;
    return '=';
  }



  for (my $i = 0; $i < @networks; $i++) {
    my $n = $networks[$i];
$ESSID = $n->{'essid'};
$SENAL = int($n->{'quality'});
$TIPO = $n->{'encryption'};
#    printf "$ESSID  %02d: %-30s [%1s] (%s, %d%%)\n", $i + 1, $n->{'essid'}, quality($n), $n->{'encryption'} || 'Open', $n->{'quality'};

print "$ESSID   $SENAL  $TIPO   \n";
  }




}


o tal vez con este comando

iwlist wlan0 scan|egrep 'Address|ESSID|Channel|Encryption'

extraer esta infomacion pero en variables

Cell 01 - Address: C0:3F:AE:EE:F8:A0
Channel:6
Frequency:2.437 GHz (Channel 6)
Encryption key:on
ESSID:"NETGEAR"
Cell 02 - Address: 00:AA:BB:CC:DD:EE
Channel:6
Frequency:2.437 GHz (Channel 6)
Encryption key:on
ESSID:"RODE"
Cell 03 - Address: AB:BA:CA:DC:9E:A3
Channel:2
Frequency:2.417 GHz (Channel 2)
Encryption key:on
ESSID:"ZARA"
Cell 04 - Address: 10:20:05:45:27:90
Channel:11
Frequency:2.462 GHz (Channel 11)
Encryption key:on
ESSID:"MTM"





alguien tiene algun codigo similar en PERL para extraer ESSID, MAC, TIPO, SEÑAL

Muchas gracias.

Última edición por Melecio; 29/07/2014 a las 08:34
  #2 (permalink)  
Antiguo 29/07/2014, 08:36
Avatar de Melecio  
Fecha de Ingreso: julio-2011
Ubicación: Coahuila
Mensajes: 320
Antigüedad: 13 años, 4 meses
Puntos: 8
Respuesta: perl /sbin/iwlist scan 2>&1

ya lo encontre es este codigo

Código:
#!/usr/bin/perl
#
# wlanscan.pl
# version 0.1
#
# Written by Joey Kelly
# joeykelly.net
#
# copyright 2014
# GPL version 2
#
# I want to get and display a table of available APs.
# I did this on NetBSD once, let's see if I can replicate on Linux.

# NOTE: the iwlist docs say or said to not write scripts against it, presumably because the output will change in future versions.
# Yeah, like I'm going to listen...

use strict;
use warnings;

#my $wifi = shift || die "What is the wifi interface? Pass it as an argument to this script. Example: ./wlanscan.pl wlan0\n";
#chomp $wifi;


# let's bounce the interface first
#system "/sbin/ifconfig $wifi down";
#system "/sbin/ifconfig $wifi up";

my $scan = `/sbin/iwlist wlan0 scan`;



my @cell = split(/Cell/,$scan);
# lose the leading bogus entry
$_ = shift @cell;


foreach my $cell (@cell) {
  my ($mac, $channel, $essid, $encryption, $mode, $signalnumbers, $signalquality, $security) = ('','','','','','','','');

  if ( $cell =~ /Address:\ ([A-Z0-9]{2}:[A-Z0-9]{2}:[A-Z0-9]{2}:[A-Z0-9]{2}:[A-Z0-9]{2}:[A-Z0-9]{2})/ ) {
    $mac = $1;
  }
  if ( $cell =~ /Channel:(\d+)/ ) {
    $channel = $1;
  }
  if ( $cell =~ /ESSID:"(\w+)"/ ) {
    $essid = $1;
  }
  $essid = '<hidden>' unless $essid;
  if ( $cell =~ /Encryption\ key:(\w+)/ ) {
    $encryption = $1;
  }
  if ( $cell =~ /Mode:(\w+)/ ) {
    $mode = $1;
  }
  if ( $cell =~ /Signal\ level=(-\d+\ dBm)/ ) {
    $signalnumbers = $1;
  }
  if ( $cell =~ /Quality=(\d+\/\d+)/ ) {
    $signalquality = $1;
  }
  #
  # OK, here's where it gets weird
  unless ( $cell =~ /WPA/ ) {
    $security = 'WEP';
  }
  if ( $cell =~ /IE:\ IEEE\ 802\.11i\/WPA2 Version\ 1/ ) {
    $security = 'WPA2 v1';
  }
  if ( $cell =~ /IE:\ IEEE\ 802\.11i\/WPA2 Version\ 2/ ) {
    $security = 'WPA2 v2';
  }
  if ( $cell =~ /IE:\ WPA\ Version\ 1/ ) {
    if ($security) {
      $security .= ' and WPA1';
    } else {
      $security = 'WPA1';
    }
  }
  # our fall-through
  $security = 'none' unless $encryption eq 'on';

  print "essid: $essid\n";
  print "channel: $channel\n";
  print "MAC: $mac\n";
  print "mode: $mode\n";
  print "encrypted: $encryption\n";
  print "security: $security\n";
  print "signal: $signalnumbers\n";
  print "quality: $signalquality\n";
  print "\n";
}

my $cells = @cell;
print "number of cells seen: $cells\n" if $cells;

funciona muy bien y me da todo lo que necesito, espero y les sirvan, Gracias,

Etiquetas: 2-1, perl
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:39.