IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Perl Discussion :

Perl XML::Twig Besoin d'aide


Sujet :

Langage Perl

  1. #1
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 18
    Points : 14
    Points
    14
    Par défaut Perl XML::Twig Besoin d'aide
    Bonjour,

    J’essaie d'afficher les données d'un XML (Résultat d'un sslscan) pour par la suite placer ce résultat en base de donner.

    Mon problème est que je n'arrive pas à récupérer mes données proprement.
    Voilà mon fichier XML :
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    <?xml version="1.0" encoding="UTF-8"?>
    <document title="SSLScan Results" version="1.11.8-static" web="http://github.com/rbsec/sslscan">
        <ssltest host="googleapis.com" port="443">
            <renegotiation supported="1" secure="1" />
            <compression supported="0" />
            <heartbleed sslversion="TLSv1.2" vulnerable="0" />
            <heartbleed sslversion="TLSv1.1" vulnerable="0" />
            <heartbleed sslversion="TLSv1.0" vulnerable="0" />
            <cipher status="preferred" sslversion="TLSv1.2" bits="128" cipher="ECDHE-RSA-AES128-GCM-SHA256" id="0xC02F" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="ECDHE-RSA-AES128-SHA" id="0xC013" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="AES128-GCM-SHA256" id="0x9C" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="AES128-SHA" id="0x2F" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="112" cipher="DES-CBC3-SHA" id="0xA" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="ECDHE-RSA-AES256-GCM-SHA384" id="0xC030" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="ECDHE-RSA-AES256-SHA" id="0xC014" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="AES256-GCM-SHA384" id="0x9D" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="AES256-SHA" id="0x35" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="ECDHE-RSA-AES128-SHA256" id="0xC027" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="ECDHE-RSA-AES256-SHA384" id="0xC028" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="128" cipher="AES128-SHA256" id="0x3C" />
            <cipher status="accepted" sslversion="TLSv1.2" bits="256" cipher="AES256-SHA256" id="0x3D" />
            <cipher status="preferred" sslversion="TLSv1.1" bits="128" cipher="ECDHE-RSA-AES128-SHA" id="0xC013" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.1" bits="128" cipher="AES128-SHA" id="0x2F" />
            <cipher status="accepted" sslversion="TLSv1.1" bits="112" cipher="DES-CBC3-SHA" id="0xA" />
            <cipher status="accepted" sslversion="TLSv1.1" bits="256" cipher="ECDHE-RSA-AES256-SHA" id="0xC014" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.1" bits="256" cipher="AES256-SHA" id="0x35" />
            <cipher status="preferred" sslversion="TLSv1.0" bits="128" cipher="ECDHE-RSA-AES128-SHA" id="0xC013" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.0" bits="128" cipher="AES128-SHA" id="0x2F" />
            <cipher status="accepted" sslversion="TLSv1.0" bits="112" cipher="DES-CBC3-SHA" id="0xA" />
            <cipher status="accepted" sslversion="TLSv1.0" bits="256" cipher="ECDHE-RSA-AES256-SHA" id="0xC014" curve="P-256" ecdhebits="256" />
            <cipher status="accepted" sslversion="TLSv1.0" bits="256" cipher="AES256-SHA" id="0x35" />
                <certificate>
                    <signature-algorithm>sha256WithRSAEncryption</signature-algorithm>
                    <pk error="false" type="RSA" bits="2048" />
                    <subject><![CDATA[*.googleapis.com]]></subject>
                    <altnames><![CDATA[DNS:*.googleapis.com, DNS:*.clients6.google.com, DNS:*.cloudendpointsapis.com, DNS:cloudendpointsapis.com, DNS:googleapis.com]]></altnames>
                    <issuer><![CDATA[Google Internet Authority G2]]></issuer>
                    <self-signed>false</self-signed>
                    <not-valid-before>Dec 15 13:50:52 2016 GMT</not-valid-before>
                    <not-valid-after>Mar  9 13:35:00 2017 GMT</not-valid-after>
                    <expired>false</expired>
                </certificate>
        </ssltest>
    </document>

    Voilà mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
    #!/usr/bin/env perl
    use strict;
    use utf8;
    use warnings qw(all);
    use Data::Dumper;
    use XML::Twig;
     
    my $FichierXML = 'test.xml';
     
    my $twig = XML::Twig->new();
    $twig->parsefile($FichierXML);
     
    my $root = $twig->root;
    my $ssltest = $root->first_child('ssltest');
     
    $ssltest->print;
    print "\n\n\n";
     
    print "ssltest-compression-supported = $ssltest->first_child('compression')->att('supported')\n";
    print "ssltest-renegotiation-secure = $ssltest->first_child('renegotiation')->att('secure')\n";
    print "ssltest-renegotiation-supported = $ssltest->first_child('renegotiation')->att('supported')\n";
    print "ssltest-certificate-self-signed = $ssltest->first_child('certificate')->field('self-signed')\n";
    print "ssltest-certificate-not-valid-after = $ssltest->first_child('certificate')->field('not-valid-after')\n";
    print "ssltest-certificate-pk-error = $ssltest->first_child('certificate')->first_child('pk')->att('error')\n";
    print "ssltest-certificate-pk-bits = $ssltest->first_child('certificate')->first_child('pk')->att('bits')\n";
    print "ssltest-certificate-pk-type = $ssltest->first_child('certificate')->first_child('pk')->att('type')\n";
    print "ssltest-certificate-subject = $ssltest->first_child('certificate')->field('subject')\n";
    print "ssltest-certificate-signature-algorithm = $ssltest->first_child('certificate')->field('signature-algorithm')\n";
    print "ssltest-certificate-not-valid-before = $ssltest->first_child('certificate')->field('not-valid-before')\n";
    print "ssltest-certificate-issuer = $ssltest->first_child('certificate')->field('issuer');\n";
    print "ssltest-certificate-altnames = $ssltest->first_child('certificate')->field('altnames')\n";
    print "ssltest-certificate-expired = $ssltest->first_child('certificate')->field('expired')\n";
    foreach my $heartbleed ($ssltest->child('heartbleed')) {
        print "ssltest-heartbleed-version = $heartbleed->att('sslversion')\n";
        print "ssltest-heartbleed-vulnerable = $heartbleed->att('vulnerable')\n";
    }
    foreach my $cipher ($ssltest->child('cipher')) {
        print "ssltest-cipher-status = $cipher->att('status')\n";
        print "ssltest-cipher-sslversion = $cipher->att('sslversion')\n";
        print "ssltest-cipher-bits = $cipher->att('bits')\n";
        print "ssltest-cipher-cipher = $cipher->att('cipher')\n";
        print "ssltest-cipher-id = $cipher->att('id')\n";
        print "ssltest-cipher-curve = $cipher->att('curve')\n";
        print "ssltest-cipher-ecdhebits = $cipher->att('ecdhebits')\n";
    }
    Le résultat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
    <ssltest host="googleapis.com" port="443"><renegotiation secure="1" supported="1"/><compression supported="0"/><heartbleed sslversion="TLSv1.2" vulnerable="0"/><heartbleed sslversion="TLSv1.1" vulnerable="0"/><heartbleed sslversion="TLSv1.0" vulnerable="0"/><cipher bits="128" cipher="ECDHE-RSA-AES128-GCM-SHA256" curve="P-256" ecdhebits="256" id="0xC02F" sslversion="TLSv1.2" status="preferred"/><cipher bits="128" cipher="ECDHE-RSA-AES128-SHA" curve="P-256" ecdhebits="256" id="0xC013" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="AES128-GCM-SHA256" id="0x9C" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="AES128-SHA" id="0x2F" sslversion="TLSv1.2" status="accepted"/><cipher bits="112" cipher="DES-CBC3-SHA" id="0xA" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-GCM-SHA384" curve="P-256" ecdhebits="256" id="0xC030" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-SHA" curve="P-256" ecdhebits="256" id="0xC014" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="AES256-GCM-SHA384" id="0x9D" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="AES256-SHA" id="0x35" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="ECDHE-RSA-AES128-SHA256" curve="P-256" ecdhebits="256" id="0xC027" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-SHA384" curve="P-256" ecdhebits="256" id="0xC028" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="AES128-SHA256" id="0x3C" sslversion="TLSv1.2" status="accepted"/><cipher bits="256" cipher="AES256-SHA256" id="0x3D" sslversion="TLSv1.2" status="accepted"/><cipher bits="128" cipher="ECDHE-RSA-AES128-SHA" curve="P-256" ecdhebits="256" id="0xC013" sslversion="TLSv1.1" status="preferred"/><cipher bits="128" cipher="AES128-SHA" id="0x2F" sslversion="TLSv1.1" status="accepted"/><cipher bits="112" cipher="DES-CBC3-SHA" id="0xA" sslversion="TLSv1.1" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-SHA" curve="P-256" ecdhebits="256" id="0xC014" sslversion="TLSv1.1" status="accepted"/><cipher bits="256" cipher="AES256-SHA" id="0x35" sslversion="TLSv1.1" status="accepted"/><cipher bits="128" cipher="ECDHE-RSA-AES128-SHA" curve="P-256" ecdhebits="256" id="0xC013" sslversion="TLSv1.0" status="preferred"/><cipher bits="128" cipher="AES128-SHA" id="0x2F" sslversion="TLSv1.0" status="accepted"/><cipher bits="112" cipher="DES-CBC3-SHA" id="0xA" sslversion="TLSv1.0" status="accepted"/><cipher bits="256" cipher="ECDHE-RSA-AES256-SHA" curve="P-256" ecdhebits="256" id="0xC014" sslversion="TLSv1.0" status="accepted"/><cipher bits="256" cipher="AES256-SHA" id="0x35" sslversion="TLSv1.0" status="accepted"/><certificate><signature-algorithm>sha256WithRSAEncryption</signature-algorithm><pk bits="2048" error="false" type="RSA"/><subject><![CDATA[*.googleapis.com]]></subject><altnames><![CDATA[DNS:*.googleapis.com, DNS:*.clients6.google.com, DNS:*.cloudendpointsapis.com, DNS:cloudendpointsapis.com, DNS:googleapis.com]]></altnames><issuer><![CDATA[Google Internet Authority G2]]></issuer><self-signed>false</self-signed><not-valid-before>Dec 15 13:50:52 2016 GMT</not-valid-before><not-valid-after>Mar  9 13:35:00 2017 GMT</not-valid-after><expired>false</expired></certificate></ssltest>
     
     
    ssltest-compression-supported = XML::Twig::Elt=HASH(0x2916bc8)->first_child('compression')->att('supported')
    ssltest-renegotiation-secure = XML::Twig::Elt=HASH(0x2916bc8)->first_child('renegotiation')->att('secure')
    ssltest-renegotiation-supported = XML::Twig::Elt=HASH(0x2916bc8)->first_child('renegotiation')->att('supported')
    ssltest-certificate-self-signed = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('self-signed')
    ssltest-certificate-not-valid-after = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('not-valid-after')
    ssltest-certificate-pk-error = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->first_child('pk')->att('error')
    ssltest-certificate-pk-bits = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->first_child('pk')->att('bits')
    ssltest-certificate-pk-type = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->first_child('pk')->att('type')
    ssltest-certificate-subject = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('subject')
    ssltest-certificate-signature-algorithm = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('signature-algorithm')
    ssltest-certificate-not-valid-before = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('not-valid-before')
    ssltest-certificate-issuer = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('issuer');
    ssltest-certificate-altnames = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('altnames')
    ssltest-certificate-expired = XML::Twig::Elt=HASH(0x2916bc8)->first_child('certificate')->field('expired')
    Argument "heartbleed" isn't numeric in numeric ge (>=) at /usr/local/share/perl5/XML/Twig.pm line 6914.
    ssltest-heartbleed-version = XML::Twig::Elt=HASH(0x2916d60)->att('sslversion')
    ssltest-heartbleed-vulnerable = XML::Twig::Elt=HASH(0x2916d60)->att('vulnerable')
    Argument "cipher" isn't numeric in numeric ge (>=) at /usr/local/share/perl5/XML/Twig.pm line 6914.
    ssltest-cipher-status = XML::Twig::Elt=HASH(0x2916d60)->att('status')
    ssltest-cipher-sslversion = XML::Twig::Elt=HASH(0x2916d60)->att('sslversion')
    ssltest-cipher-bits = XML::Twig::Elt=HASH(0x2916d60)->att('bits')
    ssltest-cipher-cipher = XML::Twig::Elt=HASH(0x2916d60)->att('cipher')
    ssltest-cipher-id = XML::Twig::Elt=HASH(0x2916d60)->att('id')
    ssltest-cipher-curve = XML::Twig::Elt=HASH(0x2916d60)->att('curve')
    ssltest-cipher-ecdhebits = XML::Twig::Elt=HASH(0x2916d60)->att('ecdhebits')
    Qu'ai je mal fait ? Si quelqu'un peux m'aider SVP

    Cordialement
    Franpom

  2. #2
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    print "ssltest-compression-supported = ", $ssltest->first_child('compression')->att('supported'), "\n";
    au lieu de

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    print "ssltest-compression-supported = $ssltest->first_child('compression')->att('supported')\n";

  3. #3
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 18
    Points : 14
    Points
    14
    Par défaut
    Bonjour,

    Merci pour avoir corrigé mon erreur de débutant.
    Celà fonctionne maintenant.
    Voilà le code pour ceux que cela pourrait aider :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    #!/usr/bin/env perl
    use strict;
    use utf8;
    use warnings qw(all);
    use Data::Dumper;
    use XML::Twig;
     
    my $FichierXML = 'test.xml';
     
    my $twig = XML::Twig->new();
    $twig->parsefile($FichierXML);
     
    my $root = $twig->root;
    my $ssltest = $root->first_child('ssltest');
     
    $ssltest->print;
    print "\n\n\n";
     
    print "ssltest-compression-supported = ", $ssltest->first_child('compression')->att('supported'), "\n";
    print "ssltest-renegotiation-secure = ", $ssltest->first_child('renegotiation')->att('secure'), "\n";
    print "ssltest-renegotiation-supported = ", $ssltest->first_child('renegotiation')->att('supported'), "\n";
    print "ssltest-certificate-self-signed = ", $ssltest->first_child('certificate')->field('self-signed'), "\n";
    print "ssltest-certificate-not-valid-after = ", $ssltest->first_child('certificate')->field('not-valid-after'), "\n";
    print "ssltest-certificate-pk-error = ", $ssltest->first_child('certificate')->first_child('pk')->att('error'), "\n";
    print "ssltest-certificate-pk-bits = ", $ssltest->first_child('certificate')->first_child('pk')->att('bits'), "\n";
    print "ssltest-certificate-pk-type = ", $ssltest->first_child('certificate')->first_child('pk')->att('type'), "\n";
    print "ssltest-certificate-subject = ", $ssltest->first_child('certificate')->field('subject'), "\n";
    print "ssltest-certificate-signature-algorithm = ", $ssltest->first_child('certificate')->field('signature-algorithm'), "\n";
    print "ssltest-certificate-not-valid-before = ", $ssltest->first_child('certificate')->field('not-valid-before'), "\n";
    print "ssltest-certificate-issuer = ", $ssltest->first_child('certificate')->field('issuer'), "\n";
    print "ssltest-certificate-altnames = ", $ssltest->first_child('certificate')->field('altnames'), "\n";
    print "ssltest-certificate-expired = ", $ssltest->first_child('certificate')->field('expired'), "\n";
    my @heartbleed = $ssltest->children('heartbleed');
    foreach my $heartbleed (@heartbleed) {
        print "ssltest-heartbleed-version = ", $heartbleed->att('sslversion'), "\n";
        print "ssltest-heartbleed-vulnerable = ", $heartbleed->att('vulnerable'), "\n";
    }
    my @cipher = $ssltest->children('cipher');
    foreach my $cipher (@cipher) {
        print "ssltest-cipher-status = ", $cipher->att('status'), "\n";
        print "ssltest-cipher-sslversion = ", $cipher->att('sslversion'), "\n";
        print "ssltest-cipher-bits = ", $cipher->att('bits'), "\n";
        print "ssltest-cipher-cipher = ", $cipher->att('cipher'), "\n";
        print "ssltest-cipher-id = ", $cipher->att('id'), "\n";
        if ($cipher->att('curve')) {print "ssltest-cipher-curve = ", $cipher->att('curve'), "\n";}
        if ($cipher->att('ecdhebits')) {print "ssltest-cipher-ecdhebits = ", $cipher->att('ecdhebits'), "\n";}
    }
    Cordialement
    François

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 13/10/2014, 14h26
  2. besoin d'aide pour de l'administration réseau en perl
    Par benzure dans le forum Programmation et administration système
    Réponses: 18
    Dernier message: 30/03/2006, 08h26
  3. Besoin d'aide pour langage XML
    Par begood13010 dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 26/02/2006, 20h24
  4. Besoin d'aide lié à un fichier xml et un tableau a charger..
    Par jjs dans le forum Bases de données
    Réponses: 2
    Dernier message: 28/07/2005, 14h03
  5. [langage] Script en Perl - besoin d'aide
    Par julfra dans le forum Langage
    Réponses: 8
    Dernier message: 13/05/2004, 14h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo