I made small script to parse text files for IP addresses and email addresses using preg_match_all intrusions. after execution program I get a result as IP address with missing one last digit. I can’t figure out this coding problem.
Please give me any suggestions on program code
Code:
<?php
function getdirfiles($dir, $no_dots=false)
{
$files = array();
$dh = @opendir($dir);
if ($dh!=false)
{
while (false !== ($filename = readdir($dh)))
{
$files[] = $filename;
}
if ($no_dots)
{
while(($ix = array_search('.',$files)) > -0)
unset($files[$ix]);
while(($ix = array_search('..',$files)) > -0)
unset($files[$ix]);
}
sort($files);
}
return $files;
}
$ipreg="/([1-9]{1}\d{1}|[1-9]{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])/";
$emailreg="/(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}/";
$folder = '/home/eger/udpchan/admin/test';
$files = getdirfiles($folder, true);
// Show IPs found
foreach ($files as $file) {
$contents = file_get_contents($folder."/".$file);
preg_match_all($ipreg, $contents, $ips);
$ips = array_unique($ips[0]);
print_r($ips);
}
// Show email address found
foreach ($files as $file) {
$contents = file_get_contents($folder."/".$file);
preg_match_all($emailreg, $contents, $emails);
$emails = array_unique($emails[0]);
print_r($emails);
}
//Show Files
print_r(scandir(test,true));
?>
Bookmarks