Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:29:07+00:00 2026-06-03T20:29:07+00:00

I am using inet_aton to convert IPv4 IP(216.12.207.142) to a string 3624718222. I use

  • 0

I am using inet_aton to convert IPv4 IP(216.12.207.142) to a string 3624718222. I use the following code for that:

ip_dec = unpack('>L', inet_aton(ip))[0]

Now I need to convert IPv6 ip 2001:23::207:142 to a similar string. It gives me error as it is not IPv4 address. How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:29:09+00:00Added an answer on June 3, 2026 at 8:29 pm

    This is the code I’ve uses for the purpose before. Note that it returns a 128 bit integer rather than a string (an integer is more useful in general)

    from socket import inet_pton, AF_INET6
    from struct import unpack
    
    def ip6_to_integer(ip6):
        ip6 = inet_pton(AF_INET6, ip6)
        a, b = unpack(">QQ", ip6)
        return (a << 64) | b
    

    And testing it

    >>> ip6_to_integer("2001:23::207:142")
    42540490934961530759802172199372521794L
    

    Or as a string if you must!

    >>> str(ip6_to_integer("2001:23::207:142"))
    '42540490934961530759802172199372521794'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code, more or less copy-pasted from the MSDN example of GetAdaptersAddresses
Included below is the code that I am currently using: soc1 = socket.socket(socket.AF_INET,socket.SOCK_STREAM) ADDR
Using import datetime in python, is it possible to take a formatted time/date string
I'm using an old thread to post new code which attempts to solve the
I have a socket() function call in my code.(using C language): socket(AF_INET, SOCK_STREAM, 0))
The following code is a test program wriiten to understand the behaviour of select()
By using strace and ifconfig , I found that I can set the IP
I found multiple answers that suggest using the SO_REUSEPORT socket option when multiple UDP
I have this code which I am using to check if a UDP socket
The camel book suggests that V-strings can be used for representing IPv4 addresses: $ipaddr

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.