Skip to content

Commit 24119f5

Browse files
committed
Merge pull request fzaninotto#681 from ravage84/patch-1
Do not generate special purpose IPv4s
2 parents 9ffdc01 + d38e8c1 commit 24119f5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Faker/Provider/Internet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function slug($nbWords = 6, $variableNbWords = true)
288288
*/
289289
public function ipv4()
290290
{
291-
return long2ip(mt_rand(0, 1) == 0 ? mt_rand(-2147483648, 0) : mt_rand(1, 2147483647));
291+
return long2ip(mt_rand(0, 1) == 0 ? mt_rand(-2147483648, -2) : mt_rand(16777216, 2147483647));
292292
}
293293

294294
/**

test/Faker/Provider/InternetTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ public function testIpv4()
108108
$this->assertNotFalse(filter_var($this->faker->ipv4(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
109109
}
110110

111+
public function testIpv4NotLocalNetwork()
112+
{
113+
$this->assertNotRegExp('/\A1\./', $this->faker->ipv4());
114+
}
115+
116+
public function testIpv4NotBroadcast()
117+
{
118+
$this->assertNotEquals('255.255.255.255', $this->faker->ipv4());
119+
}
120+
111121
public function testIpv6()
112122
{
113123
$this->assertNotFalse(filter_var($this->faker->ipv6(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));

0 commit comments

Comments
 (0)