473,499 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IPv6 and Python

I'm not sure if this is a question about python programming, system
administration or sockets in general...
I have the FTP server in my signature to which I'd want to add IPv6
support.
My hosting company provides me a common IPv4 address.
I'd like to set up my workstation (Windows XP or Linux Debian, doesn't
really matter) to temporarily use IPv6 for trying to add such feature
to my library (I work on both Windows XP and Linux).
Could someone point me to some resources describing how could I do
that?
Thanks in advance.
--- Giampaolo
http://code.google.com/p/pyftpdlib
Jun 27 '08 #1
8 8932
On May 2, 2:15 pm, "Giampaolo Rodola'" <gne...@gmail.comwrote:
I'm not sure if this is a question about python programming, system
administration or sockets in general...
I have the FTP server in my signature to which I'd want to add IPv6
support.
My hosting company provides me a common IPv4 address.
I'd like to set up my workstation (Windows XP or Linux Debian, doesn't
really matter) to temporarily use IPv6 for trying to add such feature
to my library (I work on both Windows XP and Linux).
Could someone point me to some resources describing how could I do
that?

Thanks in advance.

--- Giampaolohttp://code.google.com/p/pyftpdlib
Quote: "The individual computer systems must be upgraded to support
IPv6 (for example, on Windows XP and Server 2003 systems, IPv6 must be
installed as a Network Component via the Network Connections
Properties dialog box) and your routers must be upgraded to support
IPv6 protocols along with IPv4."

See http://articles.techrepublic.com.com...1-5727015.html

Python's socket module also talks about IPv6 calls here:
http://docs.python.org/lib/module-socket.html

I've never messed with this, so good luck!

Mike
Jun 27 '08 #2
My hosting company provides me a common IPv4 address.
I'd like to set up my workstation (Windows XP or Linux Debian, doesn't
really matter) to temporarily use IPv6 for trying to add such feature
to my library (I work on both Windows XP and Linux).
Could someone point me to some resources describing how could I do
that?
Information is spread widely. If you really want resources, I recommend
to google for them; there are various IPv6 howtos.

Here is how I would do it:

On Linux, "modprobe ipv6", then "ifconfig". This should display the
loopback adapter, with the address "::1". You should then be able to
listen on that address, and connect to it.

On Windows (XP SP2), "netsh int ipv6 install". Again, you should be able
to use IPv6 loopback afterwards.

If you want true connectivity to the global IPv6 internet, I recommend
SixXS (http://www.sixxs.net/). You can setup a tunnel to the IPv6 net
through your IPv4 POP, using a close IPv6 POP who participates in SixXS.
To set up the tunnel, you then use aiccu, which works really well for
me (and is packaged conveniently as a Debian package).

Regards,
Martin
Jun 27 '08 #3
Giampaolo Rodola' schrieb:
I'm not sure if this is a question about python programming, system
administration or sockets in general...
I have the FTP server in my signature to which I'd want to add IPv6
support.
My hosting company provides me a common IPv4 address.
I'd like to set up my workstation (Windows XP or Linux Debian, doesn't
really matter) to temporarily use IPv6 for trying to add such feature
to my library (I work on both Windows XP and Linux).
Could someone point me to some resources describing how could I do
that?
Python supports IPv6 out of the box if the underlying OS supports it,
too. You just have to use AF_INET6 instead of AF_INET:

import socket
sock = socket.socket(sock.AF_INET6, socket.AF_STREAM) # IPv6
sock.bind(("::1", 21)) # bind to IPv6 localhost

That's it.

Christian

Jun 27 '08 #4
On 2 Mag, 21:41, "Martin v. Löwis" <mar...@v.loewis.dewrote:
My hosting company provides me a common IPv4 address.
I'd like to set up my workstation (Windows XP or Linux Debian, doesn't
really matter) to temporarily use IPv6 for trying to add such feature
to my library (I work on both Windows XP and Linux).
Could someone point me to some resources describing how could I do
that?

Information is spread widely. If you really want resources, I recommend
to google for them; there are various IPv6 howtos.

Here is how I would do it:

On Linux, "modprobe ipv6", then "ifconfig". This should display the
loopback adapter, with the address "::1". You should then be able to
listen on that address, and connect to it.

On Windows (XP SP2), "netsh int ipv6 install". Again, you should be able
to use IPv6 loopback afterwards.

If you want true connectivity to the global IPv6 internet, I recommend
SixXS (http://www.sixxs.net/). You can setup a tunnel to the IPv6 net
through your IPv4 POP, using a close IPv6 POP who participates in SixXS.
To set up the tunnel, you then use aiccu, which works really well for
me (and is packaged conveniently as a Debian package).

Regards,
Martin
Thanks a lot. I've been able to listen on ::1:21 after having
installed IPv6 on both Windows and Linux thanks to your suggestions.
I'd like to ask one more question: is it possible to bind my server on
both IPv4 and IPv6 addresses (note: I do not use multiple threads or
processes)?
---- Giampaolo
http://code.google.com/p/pyftpdlib
Jun 27 '08 #5
In article
<80**********************************@l42g2000hsc. googlegroups.com>,
"Giampaolo Rodola'" <gn****@gmail.comwrote:
Thanks a lot. I've been able to listen on ::1:21 after having
installed IPv6 on both Windows and Linux thanks to your suggestions.
I'd like to ask one more question: is it possible to bind my server on
both IPv4 and IPv6 addresses (note: I do not use multiple threads or
processes)?
In theory, you should be able to bind your server socket to an IPv6 port
and have it accept connections from both IPv4 and IPV6 clients. The v4
connections will show up as IPv4-mapped IPv6 addresses (i.e. with a
::ffff/96 prefix). In practice, support for this is spotty. The Wikipedia
IPv4_mapped_address article claims, for example, that no windows OS prior
to vista supports it.

In the application I work on, we've avoided this. We just listen on two
separate sockets (one for each address family). We wrote a DualSocket
class which manages the two underlying single-protocol sockets and makes
them appear to be a single dual-protocol socket. It was a lot of user code
to write, compared with using the mapped address mechanism, but at least
it's portable to every OS we've seen that support IPv6.

You don't need multi-threading to handle multiple sockets. In our
implementation, for example, we use select() in a single thread to
multiplex the two.
Jun 27 '08 #6
Thanks a lot. I've been able to listen on ::1:21 after having
installed IPv6 on both Windows and Linux thanks to your suggestions.
I'd like to ask one more question: is it possible to bind my server on
both IPv4 and IPv6 addresses (note: I do not use multiple threads or
processes)?
You can, of course, open two sockets, and bind one for IPv4 and one for
IPv6. If you then want to use a single thread only, you need to use
poll/select, which will return when there is an incoming connection on
either socket. You then accept() the new connection for the respective
listen socket.

There is a notion of "mapped" IPv4 addresses, which allows to have a
single IPv6 server socket accept both IPv4 and IPv6 connections.
How this precisely works depends on the operating system.

On Linux, "mapped" addresses are the default. Open a v6 socket, and
connect to it through a v4 client, and it will just work. For this,
you need to specify the "any" server address, i.e.

pys = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
pys.bind(('', 1234))
pys.listen(100)
pys.accept()
(<socket._socketobject object at 0xb7d90304>, ('::ffff:77.132.228.129',
43491, 0, 0))
pys.accept()
(<socket._socketobject object at 0xb7d90bc4>, ('2001:6f8:900:a85::2',
40800, 0, 0))

The first connection was from a v4 client; the second connection from
a v6 client. To *disable* mapped addresses, you need to set the
IPV6_V6ONLY socket option to 1.

On Windows XP (including SP2), mapped addresses are not supported.

On Windows Vista, mapped addresses are supported, but you have
to explicitly *enable* a socket for mapped use, by setting
the IPV6_V6ONLY option to 0.

So in short, you should always set the IPV6_V6ONLY to 0, as the
system defaults vary. If that option is not defined in the socket
module, the system does not support mapped sockets.

Unfortunately, there is an exception to the last rule: on Vista,
the option is supported, but Python won't magically know what the
option numeric value is. So on Windows, you need to define
IPV6_V6ONLY yourself (the value is 27), and check whether the
setsockopt call succeeds.

Regards,
Martin
Jun 27 '08 #7
On 3 Mag, 05:38, Roy Smith <r...@panix.comwrote:
In the application I work on, we've avoided this. *We just listen on two
separate sockets (one for each address family). *We wrote a DualSocket
class which manages the two underlying single-protocol sockets and makes
them appear to be a single dual-protocol socket. *It was a lot of user code
to write, compared with using the mapped address mechanism, but at least
it's portable to every OS we've seen that support IPv6.

You don't need multi-threading to handle multiple sockets. *In our
implementation, for example, we use select() in a single thread to
multiplex the two.
I would be very interested in taking a look at how you implemented
that part of code. Would it be possible?
For now I wrote this and it seems to work just fine.
Any advice about it?

class FTPServer(asyncore.dispatcher):

def __init__(self, address, handler):
"""Initiate the FTP server opening listening on address.

- (tuple) address: the ip:port pair on which to listen
for ftp data connections.
- (classobj) handler: the handler class to use.
"""
asyncore.dispatcher.__init__(self)
self.handler = handler
host, port = address
for res in socket.getaddrinfo(host, port, 0,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
self.create_socket(af, socket.SOCK_STREAM)
except socket.error, msg:
if self.socket:
self.socket.close()
self.socket = None
continue
break
if not self.socket:
raise socket.error, msg
self.address_family = af

if os.name not in ('nt', 'ce'):
self.set_reuse_addr()
self.bind(address)
self.listen(5)

def handle_accept(self):
sock_obj, addr = self.accept()
log("[]%s:%s Connected." %addr[0:2])
handler = self.handler(sock_obj, self)
--- Giampaolo
http://code.google.com/p/pyftpdlib/
Jun 27 '08 #8
In article "Giampaolo Rodola'" <gn****@gmail.comwrote:
I would be very interested in taking a look at how you implemented
that part of code. Would it be possible?
Sadly, no. It's proprietary code. But, it's really not that complicated
to reconstruct, once you know the basic idea. You have a DualSocket class
whose constructor creates two sockets. It exposes (roughly) the same
interface as a socket object, but decides which underlying
protocol-specific socket to delegate to based on the address family of the
sockaddr you give it.

Oh, yeah, this was done in C++, but there's nothing really that's language
specific in the implementation.
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1781
by: Agent | last post by:
I would like to invite you and your associates to attend the US IPv6 (Internet Protocol version 6) Summit, December 8-11, 2003 in Crystal City, VA, near the Pentagon. This major opportunity to...
7
5894
by: Torsten Schmidt | last post by:
Hi, I'm trying to connect to a mysql-Server using PHP's mysql-function mysql_connect. The host on which the mysql-server is running is not the same as the host apache and php are running on. The...
8
2521
by: John Burton | last post by:
I'm not sure if this is a question about python socket support or sockets in general ... I have a socket server with which I want to accept incoming connections on ipv4 and ipv6. I've found...
0
1187
by: Carl-Johan Kjellander | last post by:
I have a problem. I want to use httplib to a site that has both IPv4 and IPv6 connectivity, hence it has both A and AAAA records. Is there a way to force httplib to use IPv6 only, or to at least...
2
3006
by: gregory_may | last post by:
First the research links: IPv6 spec (look for 'jumbo payload'): http://www.cs-ipv6.lancs.ac.uk/ipv6/documents/rfcs/archive/rfc1883.txt IPv6 Sample C# Client/Server...
3
6227
by: jiri.juranek | last post by:
Hello, is there any common function for validation if string contains valid ip address(both ipv4 and ipv6)? Or does sb wrote some regular expression for this? thanks J
3
1827
by: Pramod TK | last post by:
Hello All, I have some queries related to python support for IPv6. Can you kindly clarify the doubts which I have - 1. Does python support IPv6? 2. Does it support setting of QoS flags? 3. Does...
2
2035
by: cychong | last post by:
Hi, There is no probleming in programming the basic IPv6 socket program with the python. Then how about the IPv6 extension header? The RFC 2292 and man pages from the unix/linux advise to use...
2
3709
by: Prabhu Gurumurthy | last post by:
Hello list, I would like to parse IPv6 addresses and subnet using re module in python. I am able to either parse the ipv6 address or ipv6 network but not both using single line. any help...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.