Coder Social home page Coder Social logo

ipcalc's People

Contributors

bazhil avatar dutchy- avatar jwineinger avatar l1ghtn1ng avatar mattbennett avatar pylover avatar skion avatar tehmaze avatar tobbez avatar twinshadow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ipcalc's Issues

ipcalc 0.4.1 package is broken

It needs a README.rst file inside it, as referred to by the setup.py.

Getting distribution for 'ipcalc'.
error: README.rst: No such file or directory
An error occured when trying to install ipcalc 0.4.1. Look above this message for any errors that were output by easy_install.

doctests fail

Currently there are failing two tests: Especially the second test is important. Is it a typo?


File "ipcalc.py", line 361, in ipcalc.IP.clone
Failed example:

ip.clone()

Expected:

<ipcalc.IP object at 0xb7d4d18c>

Got:

<ipcalc.IP object at 0x980504c>

File "ipcalc.py", line 534, in ipcalc.Network.iter
Failed example:

for ip in Network('192.168.114.0.40'):
    print str(ip)

Exception raised:

Traceback (most recent call last):
  File "/usr/lib/python2.7/doctest.py", line 1254, in __run
    compileflags, 1) in test.globs
  File "<doctest ipcalc.Network.__iter__[0]>", line 1, in <module>
    for ip in Network('192.168.114.0.40'):
  File "ipcalc.py", line 161, in __init__
    self.ip = self._dqtoi(ip)
  File "ipcalc.py", line 301, in _dqtoi
    raise ValueError, "%r: IPv4 address invalid: more than 4 bytes" % dq
ValueError: '192.168.114.0.40': IPv4 address invalid: more than 4 bytes

2 items had failures:
1 of 2 in ipcalc.IP.clone
1 of 1 in ipcalc.Network.__iter__
_Test Failed_ 2 failures.

invalid syntax on python 3.4.1

Hi
I am trying to install ipcalc with pip on python version 3.4.1 and get this message:

Installing collected packages: ipcalc
Running setup.py install for ipcalc
File "C:\Python34\Lib\site-packages\ipcalc.py", line 237
if ip > 0xffffffffffffffffffffffffffffffffL:
^
SyntaxError: invalid syntax

Is it possible, that you can fix that?

Kind regard
Adrian

python3 support

Do you plan to support python3? I have problems using this library in archlinux with python3.

/31 network is still not working

Cygwin ~ $ ic 1.1.1.1/31
first host: 1.1.1.1/31
last host.: 1.1.1.2

The bug report for this initially:#17 The fix is not correct as seen above.

Incorrect cast to IP in Network class comparisons

There is a cast to IP when comparing (e.g. __eg__(), __lt__(), etc...) in the Network class. I suspect this is a copy-n-paste error?

Anyhow, changing from IP(other).size() to Network(other).size() solved my problem when comparing instances of network classes.

BR
Markus

/31 network is still incorrect

Cygwin ~ $ ic 1.1.1.1/31
first host: 1.1.1.1/31
last host.: 1.1.1.2

The bug report for this initially:#17 The fix is not correct as seen above.
This may be a fix for the above bug:

def host_first(self):
    if (self.version() == 4 and self.mask > 30) or \
            (self.version() == 6 and self.mask > 126):
         -return self
         +return self.network()
...
def host_last(self):
    """Last available host in this subnet."""
    if (self.version() == 4 and self.mask == 32) or \
    ...
    elif (self.version() == 4 and self.mask == 31) or \
            (self.version() == 6 and self.mask == 127):
        -return IP(int(self) + 1, version=self.version())
        +return IP(int(self.network()) + 1, version=self.version())

Negative indices don't work as I would expect

If I try to use a negative indice it subtracts from the IP subnet instead of returning an IP from the end of netblock.

For example:

foo1 = ipcalc.Network('192.243.234.0/29')
print foo1[-1]
192.243.233.255

I would expect it to return 192.243.234.7 which is the last IP in the 192.243.234.0/29 netblock.

This may be working as expected but it would be very handy to be able to indices IPs from the end of the subnet moving toward the beginning.

Incompatible integer op

This line:

netmask = 0x100000000 - 2**(32-self.mask)

should not use exponentiation, it should use bit-shifts. Exponents coerce the expression to float and the code after fails when it tries to use "&".

__init__ does not gracefully handle getting NoneType via eq

Probably should return a ValueError, or some such when init is passed None?

[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

> > > from ipcalc import *
> > > ip = IP(u'10.157.199.130/25')
> > > ip in [ None ]
> > > Traceback (most recent call last):
> > >   File "<stdin>", line 1, in <module>
> > >   File "/Library/Python/2.7/site-packages/ipcalc.py", line 351, in **eq**
> > >     return long(self) == long(IP(other))
> > >   File "/Library/Python/2.7/site-packages/ipcalc.py", line 156, in **init**
> > >     if '/' in ip:
> > > TypeError: argument of type 'NoneType' is not iterable```

Mixed address (or 4-in-6) not parsed correctly

When parsing a mixed (or 4-in-6) address the '6' part is stripped and only the IPv4 part is returned in the resulting integer.

Eg (using ipython):
In [1]: from ipcalc import IP

In [2]: x = IP("fd::0.0.0.1")

In [3]: x.ip
Out[3]: 1

No license

There is no source code license specified for this project.

Does not calculate Cisco style wildcard masks.

I would like to request that this library generates Cisco style wildcard masks, possibly with Network.wildcard().
For example, 10.1.1.1/30 = 10.1.1.1/255.255.255.252 with a wildcard mask of 0.0.0.3.

truncated network names are not correctly handled

for example the nestat -nr command on OSX outputs truncated network names where for example 10.255/20 is considered to be equivalent of 10.255.0.0/20. For ipcalc these are not treated equally:

>>> n = ipcalc.Network("10.255/20")
>>> n.host_first(), n.host_last()
(IP('10.0.0.1'), IP('10.0.15.254'))

>>> n = ipcalc.Network("10.255.0.0/20")
>>> n.host_first(), n.host_last()
(IP('10.255.0.1'), IP('10.255.15.254'))
(python-env)date:~ noa$ pip list |grep ipcalc
ipcalc (1.1.3)

Cannot iterate over IPv6 address in ipcalc.Network()

import ipcalc
foo = ipcalc.Network('fd00:dead:ca7:cafe::1/64')
foo.__iter__().next()
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.7/site-packages/ipcalc.py", line 544, in __iter__
    for ip in (IP(long(self)+x) for x in xrange(0, self.size())):
OverflowError: Python int too large to convert to C long

small typo prevents comparing IPs

There is a typo in line 169:

    # Netmask is numeric CIDR subnet
    elif type(self.mask) in [int, long] or self.mask.isdigit():
        self.mask = int(mask) # typo!!!

The line should read:

        self.mask = int(self.mask)

dealing with 31-bit subnet masks(with suggested code attached)

RFC 3021 specifies an exception to this rule when dealing with 31-bit subnet masks (i.e. 1-bit host identifiers). In such networks, usually point-to-point links, only two hosts (the end points) may be connected and a specification of network and broadcast addresses is not necessary.

suggested addition to host first:
def host_first(self):
if (self.version() == 4 and self.mask == 31) or (self.version() == 6 and self.mask == 127):
return self.network()

suggested addition to host last:
def host_last(self):
if (self.version() == 4 and self.mask == 31) or (self.version() == 6 and self.mask == 127):
return self.broadcast()

Strange subnet calculations

I think you are doing strange calculations. (You aren't doing things with binary (and,or,xor) operations?)
The three following examples are plain wrong.

Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import ipcalc
ipcalc.version
'0.5'
from ipcalc import Network
n = Network("129.0.0.0/2")
"128.0.0.0" in n
False
n.in_network("128.0.0.1")
False
"192.0.0.0" in n
True

Network iteration gives one IP too many

How to reproduce:

for ip in Network('127.0.0.1/24'):
    print ip

Last line prints 127.0.1.0 which it shouldn't.

Solution: * EDIT:* does not work!

def __iter__(self):
    # ...
    for ip in (IP(long(self)+x) for x in xrange(0, self.size())):
        yield ip

Change to:

    for ip in (IP(long(self)+x) for x in xrange(0, self.size()-1)):

This module are doing incorrect.

Using software ipcal:

willian_pires@wpsXPS:~/Programas/python3/IPS_FROM_REGION$: ipcalc 31.135.244.0/21
Address: 31.135.244.0 00011111.10000111.11110 100.00000000
Netmask: 255.255.248.0 = 21 11111111.11111111.11111 000.00000000
Wildcard: 0.0.7.255 00000000.00000000.00000 111.11111111
=>
Network: 31.135.240.0/21 00011111.10000111.11110 000.00000000
HostMin: 31.135.240.1 00011111.10000111.11110 000.00000001
HostMax: 31.135.247.254 00011111.10000111.11110 111.11111110
Broadcast: 31.135.247.255 00011111.10000111.11110 111.11111111
Hosts/Net: 2046 Class A

This is network address: 31.135.240.0/21 and this is BroadCast Address: 31.135.247.255

When i run this code:
import ipcalc
address = '31.135.244.0/21'
c = ipcalc.Network(address)
print(c.broadcast,c.network)

it produce:
<bound method Network.broadcast of Network('31.135.244.0/21')>
<bound method Network.network of Network('31.135.244.0/21')>

Look at Network address is not 31.135.240.0/21

Subnet in subnet

Hello,

Using python2.6 (centos6) I've found the following:

$ python
Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipcalc
>>> subnet = ipcalc.Network('128.121.0.0/16')
>>> rentry = ipcalc.Network('128.121.159.48/28')
>>> subnet in rentry
True
>>> rentry in subnet
True

And it's ipcalc version 1.1.3

Are you exactly sure that the above expression should return true in both direction? Personally I think a /16 should have difficulties in being a subset of a /28. It's very hard to create a /28 superset which covers a /16.

in_network

This was brought up in issue #4, but I was still getting strange results from in_network(). Below works well enough for my purposes, but I'm really rather new to Python.

    def in_network(self, other):
        '''
        Check if the given IP address is within this network.
        '''
        other = Network(other)
        return(long(self.netmask())&long(self) == long(self.netmask())&long(other))

Edit: Above code edited to actually mask address and compare network. It returns true for network and broadcast addresses which I'm not sure is desired.

Request for additional special IP ranges (from RFCs)

Consider adding additional special _range identifications for IPv4 subnets commonly used in the telecom industry:

  • Multicast SSM (RFC 3569): 232.0.0.0/8 and FF3x::/96
  • TEST-NET (RFC 5737): 192.0.2.0/24
  • TEST-NET2 & TEST-NET3 (RFC 5737): 198.51.100.0/24 and 203.0.113.0/24
  • 6to4 anycast (RFC 3068): 192.88.99.0/24
  • Autoconfiguration (RFC 6890): 169.254.0.0/16
  • DS-Lite (RFC 6333): 192.0.0.0/29

A non-exhaustive list is here:
http://en.wikipedia.org/wiki/Reserved_IP_addresses

No way to resolve IP + Netmask to Network Object

ipcalc doesn't correctly calculate usable IP space if you supply a usable IP address into the Network IP variable.

For example:

for x in ipcalc.Network("192.168.1.5",mask=24):
    print x

returns

192.168.1.5
192.168.1.6
192.168.1.7
192.168.1.8
192.168.1.9
192.168.1.10
192.168.1.11
192.168.1.12
192.168.1.13
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
192.168.1.18
192.168.1.19
192.168.1.20
192.168.1.21
192.168.1.22
192.168.1.23
192.168.1.24
192.168.1.25
192.168.1.26
192.168.1.27
192.168.1.28
192.168.1.29
192.168.1.30
192.168.1.31
192.168.1.32
192.168.1.33
192.168.1.34
192.168.1.35
192.168.1.36
192.168.1.37
192.168.1.38
192.168.1.39
192.168.1.40
192.168.1.41
192.168.1.42
192.168.1.43
192.168.1.44
192.168.1.45
192.168.1.46
192.168.1.47
192.168.1.48
192.168.1.49
192.168.1.50
192.168.1.51
192.168.1.52
192.168.1.53
192.168.1.54
192.168.1.55
192.168.1.56
192.168.1.57
192.168.1.58
192.168.1.59
192.168.1.60
192.168.1.61
192.168.1.62
192.168.1.63
192.168.1.64
192.168.1.65
192.168.1.66
192.168.1.67
192.168.1.68
192.168.1.69
192.168.1.70
192.168.1.71
192.168.1.72
192.168.1.73
192.168.1.74
192.168.1.75
192.168.1.76
192.168.1.77
192.168.1.78
192.168.1.79
192.168.1.80
192.168.1.81
192.168.1.82
192.168.1.83
192.168.1.84
192.168.1.85
192.168.1.86
192.168.1.87
192.168.1.88
192.168.1.89
192.168.1.90
192.168.1.91
192.168.1.92
192.168.1.93
192.168.1.94
192.168.1.95
192.168.1.96
192.168.1.97
192.168.1.98
192.168.1.99
192.168.1.100
192.168.1.101
192.168.1.102
192.168.1.103
192.168.1.104
192.168.1.105
192.168.1.106
192.168.1.107
192.168.1.108
192.168.1.109
192.168.1.110
192.168.1.111
192.168.1.112
192.168.1.113
192.168.1.114
192.168.1.115
192.168.1.116
192.168.1.117
192.168.1.118
192.168.1.119
192.168.1.120
192.168.1.121
192.168.1.122
192.168.1.123
192.168.1.124
192.168.1.125
192.168.1.126
192.168.1.127
192.168.1.128
192.168.1.129
192.168.1.130
192.168.1.131
192.168.1.132
192.168.1.133
192.168.1.134
192.168.1.135
192.168.1.136
192.168.1.137
192.168.1.138
192.168.1.139
192.168.1.140
192.168.1.141
192.168.1.142
192.168.1.143
192.168.1.144
192.168.1.145
192.168.1.146
192.168.1.147
192.168.1.148
192.168.1.149
192.168.1.150
192.168.1.151
192.168.1.152
192.168.1.153
192.168.1.154
192.168.1.155
192.168.1.156
192.168.1.157
192.168.1.158
192.168.1.159
192.168.1.160
192.168.1.161
192.168.1.162
192.168.1.163
192.168.1.164
192.168.1.165
192.168.1.166
192.168.1.167
192.168.1.168
192.168.1.169
192.168.1.170
192.168.1.171
192.168.1.172
192.168.1.173
192.168.1.174
192.168.1.175
192.168.1.176
192.168.1.177
192.168.1.178
192.168.1.179
192.168.1.180
192.168.1.181
192.168.1.182
192.168.1.183
192.168.1.184
192.168.1.185
192.168.1.186
192.168.1.187
192.168.1.188
192.168.1.189
192.168.1.190
192.168.1.191
192.168.1.192
192.168.1.193
192.168.1.194
192.168.1.195
192.168.1.196
192.168.1.197
192.168.1.198
192.168.1.199
192.168.1.200
192.168.1.201
192.168.1.202
192.168.1.203
192.168.1.204
192.168.1.205
192.168.1.206
192.168.1.207
192.168.1.208
192.168.1.209
192.168.1.210
192.168.1.211
192.168.1.212
192.168.1.213
192.168.1.214
192.168.1.215
192.168.1.216
192.168.1.217
192.168.1.218
192.168.1.219
192.168.1.220
192.168.1.221
192.168.1.222
192.168.1.223
192.168.1.224
192.168.1.225
192.168.1.226
192.168.1.227
192.168.1.228
192.168.1.229
192.168.1.230
192.168.1.231
192.168.1.232
192.168.1.233
192.168.1.234
192.168.1.235
192.168.1.236
192.168.1.237
192.168.1.238
192.168.1.239
192.168.1.240
192.168.1.241
192.168.1.242
192.168.1.243
192.168.1.244
192.168.1.245
192.168.1.246
192.168.1.247
192.168.1.248
192.168.1.249
192.168.1.250
192.168.1.251
192.168.1.252
192.168.1.253
192.168.1.254
192.168.1.255
192.168.2.0
192.168.2.1
192.168.2.2
192.168.2.3
192.168.2.4

while technically correct with the given inputs, the more common use-case would be for someone to attempt to resolve a usable IP address space of an IP + Netmask. I didn't see a way to retrieve the Network Address from the IP object which would solve the problem here.

I would hope that we can do something like this:

for x in ipcalc.IP("192.168.1.1", mask=24).network():
print x

Unable to parse ipv6 addresses which have zone IDs

File "/Users/nagakasu/deploy/uRevenue/env/lib/python2.7/site-packages/ipcalc.py", line 152, in __init__ self.ip = self._dqtoi(ip) File "/Users/nagakasu/deploy/uRevenue/env/lib/python2.7/site-packages/ipcalc.py", line 278, in _dqtoi if not 0 <= int(h, 16) <= 0xffff: ValueError: invalid literal for int() with base 16: '1%lo0'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.