Tags: DBI

Sort by: Date / Title /

  1. 11 years ago by toff
    Utilisation de INET_ATON de MySQL pour trier sur les IP
    1. #!/usr/bin/perl -w
    2. use strict;
    3. use warnings;
    4. use DBI;
    5.  
    6. #Connection à la base de donnes OCS
    7. my $dns = 'dbi:mysql:ocsweb:localhost';
    8. my $login = 'root';
    9. my $passwd = 'secret';
    10. my $dbh = DBI->connect($dns, $login, $passwd) or die "Connection impossible: $DBI::errstr\n";
    11.  
    12. # Recuperation des IP et des MAC  des postes SANS "Anti-virus"
    13. my $query = "SELECT DISTINCT hard.NAME, net.IPADDRESS, net.MACADDR ".
    14.                 "FROM softwares AS soft, hardware AS hard, networks AS net ".
    15.                 "WHERE hard.ID = soft.HARDWARE_ID ".
    16.                   "AND hard.ID = net.HARDWARE_ID ".
    17.                   "AND net.STATUS = 'up' ".
    18.                   "AND soft.name NOT LIKE '%anti-virus%' ".
    19.                 "ORDER BY INET_ATON(net.IPADDRESS) ";
    20.  
    21. my $result = $dbh->prepare($query) or die "Preparation impossible: $DBI::errstr\n";
    22.  
    23. $result->execute() or die "Execution impossible: $DBI::errstr\n";
    24.  
    25. #$result->dump_results();
    26.  
    27. printf ("Il y a %d correspondances:\n",$result->rows);
    28.  
    29. while ( my ($name, $ip, $mac) = $result->fetchrow_array()){
    30.         print "$name, \t$ip, \t$mac\n";
    31. }
    32. $result->finish();
    33. $dbh->disconnect();
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/513"></script>

First / Previous / Next / Last / Page 1 of 1 (1 posteets)