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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:37:59+00:00 2026-05-27T18:37:59+00:00

I am looking for a function to determine whether a given IPv4 address is

  • 0

I am looking for a function to determine whether a given IPv4 address is in a given network.

It will be similar to this; however, I do not want to install a complete framework or reinvent the wheel if it is not necessary.

The idea would be similar to the following:

function IsInNetwork($givenIP, $networkIP, $netmask) {
   // ???
}

$valid = IsInNetwork("10.0.9.35", "10.0.8.0", "255.255.254.0");

— EDIT —

With Rich Adams help, he pointed me in the right direction and came up with the following:

function IsInNetwork2($givenIP, $networkIP, $netmask) 
{
    $ipaddr = ip2long($givenIP);
    $netip = ip2long($networkIP);
    $netmask = (ip2long($netmask) * -1) + $netip;

    if ($ipaddr >= $netip && $ipaddr <= $netmask){
        return true;
    } else {
        return false;
    }
}
  • 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-27T18:38:00+00:00Added an answer on May 27, 2026 at 6:38 pm

    Something like this should work,

    function IsInNetwork($givenIP, $networkIP, $netmask)
    {
        return ((ip2long($givenIP) & ip2long($networkIP)) == ip2long($network));
    }
    
    $valid = IsInNetwork("10.0.9.35", "10.0.8.0", "255.255.254.0"); // true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Similar in concept to Math.Abs() - I'm looking for a function that when given
I'm looking for a similar IsStructure function. Is there some other way to determine
I am looking for a function that will tell me, for a list of
Im looking for a function that will pull the youtube duration of a video
Using PHP, given a URL, how can I determine whether it is an image?
I'm looking for an API/function I can call to determine if software is running
Whilst looking for a C++ implementation of Excel's NORMDIST (cumulative) function I found this
i tried to look up whether virtual function determine during compilation or while running.
I'me looking for a function that would receive a time and would round it
I'm looking for a function that calculates years from a date in format: 0000-00-00.

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.