Jump to content

Recommended Posts

So I have a program we use that maintains all of our IP addresses. I need to import new ip addresses into this db which in itself would be pretty easy except for the DB's tables.....

 

I need to find out if an IP address is within the correct subnet and find the subsequent subnet id.

 

I'm probably not explaining this properly.

 

Here's how the tables are layed out

 

Subnet

|-> id              (this ID is referenced by the subnetID in the next table)

|-> subnet      (in ip2long format)

|-> mask        (cidr format)

 

ipaddresses

|-> id

|-> subnetID  (matches up with the subnet table)

|-> ip_addr (in an ip2long format)

 

I need to be able to insert an ip say 10.0.0.25 and ensure that it get added to the right subnetID.  Mind you there can be multiple /29's or a single /24 etc....  

 

Please let me know if you need any more information or if I should clarify this some more.

Edited by Trip-Out

Why do you need the subnetID at all? You can always look up the appropriate subnet whenever you want, and without having to care about managing a subnetID column. Assuming there aren't overlapping subnets.

 

Store the start and end of the subnet (with an index on the two) to make it easy to JOIN:

JOIN subnet ON ipaddresses.ip_addr BETWEEN subnet.start AND subnet.end
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.