2

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!

0

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.