Skip to content

Commit

Permalink
Add 172.16/12 local IPv4 block (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan authored Dec 8, 2020
1 parent 9f12db8 commit 0d72e9f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Faker/Provider/Internet.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class Internet extends Base
'https://{{domainName}}/{{slug}}.html',
];

/**
* @link https://tools.ietf.org/html/rfc1918#section-3
*/
protected static $localIpBlocks = [
['10.0.0.0', '10.255.255.255'],
['172.16.0.0', '172.31.255.255'],
['192.168.0.0', '192.168.255.255'],
];

/**
* @example 'jdoe@acme.biz'
*/
Expand Down Expand Up @@ -204,13 +213,9 @@ public function ipv6()
*/
public static function localIpv4()
{
if (Miscellaneous::boolean()) {
// 10.x.x.x range
return long2ip(self::numberBetween(ip2long('10.0.0.0'), ip2long('10.255.255.255')));
}
$ipBlock = self::randomElement(static::$localIpBlocks);

// 192.168.x.x range
return long2ip(self::numberBetween(ip2long('192.168.0.0'), ip2long('192.168.255.255')));
return long2ip(static::numberBetween(ip2long($ipBlock[0]), ip2long($ipBlock[1])));
}

/**
Expand Down

0 comments on commit 0d72e9f

Please sign in to comment.