0

how to extract all ip address from a given string, please.

eg:

"
2014-07-08 19:05:20 1X4YpU-0001kr-6y <= info@arianet-dsl.com H=(server.takcloud.com) [185.4.28.203] P=esmtps X=TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256 S=1018 id=57844562-138B-4934-9CF7-554F8C613C1C@arianet-dsl.com
"
user229044
  • 232,980
  • 40
  • 330
  • 338
daslicht
  • 814
  • 10
  • 26

1 Answers1

3

I would use RegEx

Search for groups of up to three "{1,3}" digits "\d" separated by a "."

\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b

To use it in PHP

$mailStr = "2014-07-08 19:05:20 1X4YpU-0001kr-6y <= info@arianet-dsl.com H=(server.takcloud.com) [185.4.28.203] P=esmtps X=TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256 S=1018 id=57844562-138B-4934-9CF7-554F8C613C1C@arianet-dsl.com";
$regexpattern = "/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/";
preg_match_all($regexpattern , $mailStr, $matches);
print_r($matches);
Cheruvian
  • 5,628
  • 1
  • 24
  • 34