Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Do not generate special purpose IPv4s #681

Merged
merged 3 commits into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Faker/Provider/Internet.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function slug($nbWords = 6, $variableNbWords = true)
*/
public function ipv4()
{
return long2ip(mt_rand(0, 1) == 0 ? mt_rand(-2147483648, 0) : mt_rand(1, 2147483647));
return long2ip(mt_rand(0, 1) == 0 ? mt_rand(-2147483648, -2) : mt_rand(16777216, 2147483647));
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/Faker/Provider/InternetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ public function testIpv4()
$this->assertNotFalse(filter_var($this->faker->ipv4(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4));
}

public function testIpv4NotLocalNetwork()
{
$this->assertNotRegExp('/\A1\./', $this->faker->ipv4());
}

public function testIpv4NotBroadcast()
{
$this->assertNotEquals('255.255.255.255', $this->faker->ipv4());
}

public function testIpv6()
{
$this->assertNotFalse(filter_var($this->faker->ipv6(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
Expand Down