Skip to content

Instantly share code, notes, and snippets.

@musdevs
Last active May 5, 2017 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musdevs/33bbeec1573c0d684ea93e8577435a92 to your computer and use it in GitHub Desktop.
Save musdevs/33bbeec1573c0d684ea93e8577435a92 to your computer and use it in GitHub Desktop.
This script extracts IP-addresses from standart input
#!/usr/bin/php
<?php
$mask = '/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/';
while ($line = fgets(STDIN)) {
if (preg_match_all($mask, $line, $matches)) {
foreach ($matches[0] as $ip) {
echo $ip, PHP_EOL;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment