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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:37:41+00:00 2026-05-31T19:37:41+00:00

Before I go ahead and write something myself is anyone aware of a library

  • 0

Before I go ahead and write something myself is anyone aware of a library that can normalize a set of IP addresses. I manage an application where access is based on a range of IP address supplied from our clients. Most often this is small, but sometimes this list is 1,000+ horribly presented IP addresses.

for example

#INPUT                  #TO             #OUTPUT
192.168.0-10.*          ->        192.168.0.0-192.168.10.255
192.168.15.0-64         ->        192.168.15.0-192.168.15.64
192.10-15.*.*           ->        192.10.0.0-192.15.255.255
192.168.1.1             ->        192.168.1.1-192.168.1.1
#YES, last case needed too, 
#the scripit I have to convert to a CIDR range needs  start and stop

This would preferably be done in python, but java or some sort of shell script would work too.
After wards I already have a script I’ve written to convert to the CIDR range and store these in our permissions table. I’m really just tried of doing this by hand several times a year. I think it is time to automate this a bit, just don’t want to reinvent the wheel here. It seems this might be a common enough problem

  • 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-31T19:37:43+00:00Added an answer on May 31, 2026 at 7:37 pm

    Both answers were helpfull, but neither answer my question. Which was if there exisited a library to do this already. I haven’t found one. It may be a worthwhile method to include of one of the other libraries that exist that focus on IPs. Adam’s Iptools was something that I found before asking this question.

    My output did change a bit. I ended up returning a CIDR address and not a range. A few things could be simplified, and cleaned up. Also some error checking would be helpful. But this is what I used, with my rusty python and everything.

    def normalize(ip):
        if '/' in ip: 
            return [ip]
    
        ocets = [ocet.replace(' ','') for ocet in ip.split('.')]
        if len(ocets) == 4: ocets += ocets
        if len(ocets) == 7: 
            if (re.search('-',ocets[3])):
                for i,v in enumerate(ocets[3:]):
                    if i == 0:
                        last = ocets[4]
                        ocets[3],ocets[4] = ocets[3].split('-')
                    else:
                        if 4+i < len(ocets):
                            newVal = last
                            last = ocets[4+i]
                            ocets[4+i] = newVal
                        else: 
                            ocets.append(last)
    
        if len(ocets) != 8: 
            return 'ERROR WITH: %s not right size %d' % ('.'.join(ocets),len(ocets))
        for i,ocet in enumerate(ocets):
            if (re.search('\*',ocet)): 
                ocets[i] = '0'
                ocets[i+4] = '255'        
    
    
            if (re.search('-',ocets[i])): 
                ocets[i],ocets[i+4] = ocets[i].split('-')[0:2]
        newIP = netaddr.iprange_to_cidrs('.'.join(ocets[0:4]) ,'.'.join(ocets[4:]))
        return newIP
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an application in C that can be extended at runtime by means
Now, I could go ahead and write this using FileSystemWatcher etc, but before I
before I start I want to point out that I tagged this question as
Before asking the question let me preface with the fact that I am new
Before I ask my question, I want to mention that I am only today
Before saying anything I have to say that, albeit I'm an experienced programmer in
Before I ask the question let me state that I have attempted to google
I have .NET 3.5 application wrote in C# using NHibernate. Before I has OracleClientDriver
I'm working on an application that it's been giving me some trouble, partly because
I need to write a very basic command interpreter on a micro controller that

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.