6

Is there any function or API or method that will convert a doted IP string to decimal number?

1

1 Answer 1

16

I'm not sure what is the decimal number you really want, but take a look at socket.inet_aton. It will give you string with binary representation of the IP address in network byte order. If you want to get a regular integer out of it, you could use struct.unpack with either "!I" or "I", depending on which byte order you're interested in.

Example:

import socket, struct
print struct.unpack("!I", socket.inet_aton("127.0.0.1"))[0]

Prints: 2130706433.

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.