0

I have a log file which I want to pull IP's out of. I have tried this using preg_match() but it never finds a match. Here is my attempt:

$str = 'Jan  7 01:11:58 vps.... sshd[14799]: Disconnected from authenticating user root 11.22.333.444 port 52636 [preauth]';

if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $str, $ip_matches)) {
    var_dump($ip_matches);
}

Could anyone point me in the right direction?

Jaquarh
  • 6,493
  • 7
  • 34
  • 86

0 Answers0