Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[OFF/PHP] Extraire des ip de mes logs .. (resolu)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
dapsaille
Advocate
Advocate


Joined: 02 Aug 2004
Posts: 2366
Location: Paris

PostPosted: Tue Sep 12, 2006 6:25 pm    Post subject: [OFF/PHP] Extraire des ip de mes logs .. (resolu) Reply with quote

Bonjour à tous


voila je sais hors sujet hors sujet ... mais bon ca concerne ma gentoo favorie donc ^^

Je cherche en php à extraire les adresses ip de mes logs ..

ok ca parrait con mais ....

[dest: 70.190.235.122] connection closed (69 seconds) (UID: 199)

le fichier étant un texte brut j'ai tenté du ereg_replace("([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})"
et autres joyeusetés mais je me casse les dents

je veux juste extraire cette ip et la placer dans une variable php ..

un volontaire ? :p

EDIT= Je ne suis pas focalisé sur ereg hein pereg en perl peut le faire ou toute autres méthodes n'hésitez pas ^^


Last edited by dapsaille on Wed Sep 13, 2006 12:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
netfab
Veteran
Veteran


Joined: 03 Mar 2005
Posts: 1733
Location: 127.0.0.1

PostPosted: Wed Sep 13, 2006 9:17 am    Post subject: Reply with quote

Salut,

Quote:
$ cat log.txt
[dest: 70.190.235.122] connection closed (69 seconds) (UID: 199)
[dest: 68.80.14.72] connection closed (69 seconds) (UID: 199)


Code:
$ cat extract.php
<?php

$handle = fopen("log.txt", "r");

if ($handle) {
        while (!feof($handle)) {
                $buffer = fgets($handle, 255);

                // adresse ip
                $pattern='/([0-9]{1,3}\.){3}[0-9]{1,3}/';
                preg_match_all($pattern,$buffer,$out);

                if( $out[0][0] != "" )
                        echo "ip : ".$out[0][0]."<br />";
        }
        fclose($handle);
}

?>


Sortie :
Quote:

ip : 70.190.235.122
ip : 68.80.14.72
Back to top
View user's profile Send private message
dapsaille
Advocate
Advocate


Joined: 02 Aug 2004
Posts: 2366
Location: Paris

PostPosted: Wed Sep 13, 2006 12:42 pm    Post subject: Reply with quote

Wouhouuuuu

superbe exercice de style :roll:


avec mes plus chaleureux remerciements ^^
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum