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 8477255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:24:45+00:00 2026-06-10T18:24:45+00:00

How can I convert a netmask to a specific netmask. Example: 127.0.0.0/16 Convert to

  • 0

How can I convert a netmask to a specific netmask.

Example: 127.0.0.0/16 Convert to /24 netmask.

It should output something like:

127.0.0.0/24
127.0.1.0/24
127.0.2.0/24
127.0.2.0/24

etc. all the way up to 127.0.255.0/24.

How can this be accomplished through PHP? I found this tool: http://jodies.de/ipcalc it’s coded in PERL. How can I get similar funcitonality using PHP?

I found this: http://jasonkolpin.com/classes/ipcalc/demo.php although it seems broken.. Probably will try and fix it.

Update SOLVED: I basically run: $exec = shell_exec("/usr/local/bin/ipcalc 127.0.0.0/16 24 -b -n"); and parse out the Network: field. This basically converts 127.0.0.0/16 to all /24s.

Make sure that ipcalc is installed on the host to accomplish this. You can do this by using yum install ipcalc in CentOS, or apt-get install ipcalc in Ubuntu, or cd /usr/ports/net-mgmt/ipcalc/ && make install clean on FreeBSD 🙂

  • 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-06-10T18:24:47+00:00Added an answer on June 10, 2026 at 6:24 pm

    I’ve build a library to do IP address manipulation in pure PHP.

    You’d have to do this:

    <?php
    use Leth\IPAddress\IP;
    $current_cidr = 16;
    $desired_cidr = 24;
    $net = IP\NetworkAddress::factory('127.0.0.0', $current_cidr);
    $subnets = $net->split($desired_cidr - $current_cidr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You can convert a negative number to positive like this: int myInt = System.Math.Abs(-5);
In MSSQL you can convert a string into an integer like this: CONVERT(INT, table.column)
So I figured out I can convert an image to grayscale like this: public
Resharper 5 can convert my foreach loops to Linq queries. Which I like. But
Is there can convert the stuff read from input port to some specific type
On Linux you can convert a date like 2010-10-02 to a unix timestamp in
Is there a way I can convert an mp3 file into a wav/aiff in
How I can convert all value of element and attributes of xml to Map
how i can convert this word mamá to this word mam\U00E1
In JavaScript you can convert a number to a string representation with a specific

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.