Skip to content
Advertisement

Convert an IP string to a number and vice versa

How would I use python to convert an IP address that comes as a str to a decimal number and vice versa?

For example, for the IP 186.99.109.000 <type'str'>, I would like to have a decimal or binary form that is easy to store in a database, and then retrieve it.

Advertisement

Answer

converting an IP string to long integer:

JavaScript

the other way around:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement