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 8069269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:58:30+00:00 2026-06-05T12:58:30+00:00

I formerly used the code below to bind IPv4 address to Python socket as

  • 0

I formerly used the code below to bind IPv4 address to Python socket as source ip address.

import socket
true_socket = socket.socket
def bound_socket(*a, **k):
    sock = true_socket(*a, **k)
    sock.bind((sourceIP, 0))
    return sock
socket.socket = bound_socket

Does above code work for IPv6 address? If not, how can I bind an IPv6 address?

Thanks in advance!

  • 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-05T12:58:32+00:00Added an answer on June 5, 2026 at 12:58 pm

    you can try this, to get an IPV6 address, it is recommend that you use socket.getaddrinfo it will return all the different address both IPV4 and IPV6, you can bind them all or just which ever one you want/need.

    import socket
    def bound_socket(*a, **k):
        sock = socket.socket(*a, **k)
        if socket.AF_INET6 in a:
            if not socket.has_ipv6:
                raise ValueError("There's no support for IPV6!")
            else:
                address = [addr for addr in socket.getaddrinfo(source_ip, None)
                            if socket.AF_INET6 == addr[0]] # You ussually want the first one.
                if not address:
                    raise ValueError("Couldn't find ipv6 address for source %s" % source_ip)
                sock.bind(address[0][-1])
        else:
            sock.bind((source_ip, 0))
        return sock
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Formerly my webpage used the charset UTF-8, and it inserted a lot of content
I often write .net applications that only support one instance. Formerly I used .net-remoting
I've formerly used L2S and am looking at using NHib along with the Sharp
I used to access my Google Bookmarks, server side with this PHP code: $curlObj
We performed an upgrade of a proprietary program that formerly used Access and now
Feature explained below is available in Microsoft Dynamics AX (formerly known as Axapta), an
We are porting an app which formerly used Openbase 7 to now use MySQL
Microsoft distributes source code to reference implementations of their different Direct3D APIs to hardware
I formerly asked for a Best-Practice regarding this, But this is one the strategies
I realize that a SO user has formerly asked this question but it was

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.