Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5977333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:21:20+00:00 2026-05-22T21:21:20+00:00

knowing nothing about java (I thought a thread on this same topic for java)

  • 0

knowing nothing about java (I thought a thread on this same topic for java) and a tiny bit about php, I was wondering how I could generate, with php, a complete list of all the possible IPs (0.0.0.0 to 255.255.255.255) and then how I can use each of those in a php script that is intended to test a IP verification tool that I am trying to set up (take each one of them and use it).

For the second part of the question, I was thinking about using a foreach statement or using the part of the “testing code” inside the loop that would generate each IP combination, so that it is tested as the IPs are generated.

Then for the first part, I have to admit that I am stuck and that my basic knowledge doesn’t enable me to find a satisfying solution
So far I have come with this:

function gen() {
    $n1 = 0;
    $n2 = 0;
    $n3 = 0;
    $n4 = 0;

    while ($n4 <= 255 && $n3 <= 255) {
        echo $n1.'.'.$n2.'.'.$n3.'.'.$n4++.'<br>';
        echo $n1.'.'.$n2.'.'.$n3++.'.'.$n4.'<br>';
    }
}
gen();

which just partially does what I want.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:21:21+00:00Added an answer on May 22, 2026 at 9:21 pm

    Rather than generating a possible database / storage for ~4 billion IP4 addresses (assuming you are only looking at IPv4 ignoring all IPv6 addresses) would it not be easier, and more practical just generate random IP address combinations to test with, which you can easily validate with RegEx?

    The following regex would allow you to validate any particular IPv4 address from 0.0.0.0 to 255.255.255.255

    \b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

    What you do need to remember however is that not all combinations of addresses are classed as ‘valid’ even if they are syntax correct.

    Another alternative (as also mentioned by @binaryLV) is using the PHP filter_var($ip, FILTER_VALIDATE_IP); function which is nice and clean. Check the flags out to help filter too over at http://php.net/manual/en/function.filter-var.php

    Update

    For IP location based services I would recommend using a service such as IPInfoDB. They provide both an API (see here) to use which allows you to call their service reducing the need to store the information on your database. Else they offer a database of IP addresses (see here) to xxx.xxx.xxx precision that can also be downloaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I started working on this app knowing nothing about web development which is
Knowing nothing about the GC and never having the need to use it (or
Knowing an exception code, is there a way to find out more about what
This problem involved me not knowing enough of C++. I am trying to access
I'm done with PC RegEx and moving on to jQuery. ;) Knowing almost nothing
I feel dumb for not knowing this, but I see a lot of links
Without knowing i typed 'far' instead of 'var' by my mistake.I noticed the keyword
I'm interested in knowing how many developers use each of the major languages/platforms, but
I'm interested in knowing what high quality and useful add-ons or utilities are available
I'm interested in knowing how revision-control systems do merging. Suppose you have a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.