bmulik
bmulik

Reputation: 23

python based IP address calculator (IPCALC) code

I've the python CGI for user entered input for IP address calculation but python ipcalc is not taking input as a variable, for example I'm trying to run this code

>>> import ipcalc
>>> ip='10.84.35.11'
>>> mask=24
>>> print ip
    10.84.35.11
>>> print mask
   24
>>> subnet = ipcalc.Network(ip/mask)

It gives me an error- Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for /: 'str' and 'int'

where as if I pass the value as it is like subnet = ipcalc.Network('10.84.35.11/24') it works perfect!

I'm new to programming, can someone help to solve this!

Upvotes: 2

Views: 2384

Answers (1)

Reut Sharabani
Reut Sharabani

Reputation: 31339

You probably want a string representing a network:

subnet = ipcalc.Network("%s/%d" % (ip, mask))

Right now you're trying to use the / operator on str and int which is not defined (as the error says).

Upvotes: 2

Related Questions