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

Commit

Permalink
Merge pull request #681 from ravage84/patch-1
Browse files Browse the repository at this point in the history
Do not generate special purpose IPv4s
  • Loading branch information
fzaninotto committed Aug 26, 2015
2 parents 9ffdc01 + d38e8c1 commit 24119f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit 24119f5

Please sign in to comment.