473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ipv6 validation

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

Mar 18 '06 #1
3 6215
In article <11**********************@g10g2000cwb.googlegroups .com>,
ji**********@kctdata.cz wrote:
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


Look at socket.inet_pton(). First check to make sure ipv6 is supported on
your platform, then pass your string to inet_pton() inside of a try block
to catch socket.error. It would have been nicer is a more specific
exception was thrown, but this seems to work. For example:
socket.has_ipv6 True socket.inet_pton(socket.AF_INET6, "8001::1244") '\x80\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x12D' socket.inet_pton(socket.AF_INET6, "8001:xyz:1244") Traceback (most recent call last):
File "<stdin>", line 1, in ?
socket.error: illegal IP address string passed to inet_pton


Be aware that IPv6 support is messy on Windows. For example, if you're
running Win 2003 (or XP, I would guess), the OS does support IPv6 (and thus
socket.has_ipv6 will probably bet set to True) but the IPv6 libraries don't
actually get loaded until you configure an IPv6 address on some interface.
This means things like inet_pton() will fail, which is truly bletcherous
and evil.

Writing a regex to recognize valid IPv6 presentation strings is not
trivial. Keep in mind that you're allowed exactly 0 or 1 "::" occurrances,
and things like "ffff::192.168.11.1" are legal (I don't remember if I got
the semantics right there, but the syntax is legal).
Mar 18 '06 #2
thanks a lot for this solution.
Next thing: how may i find out that that address is multicast one? is
there some easy possibility or i have to use regex now?

thanks

Mar 30 '06 #3
On 30 Mar 2006 11:40:08 -0800, rumours say that ji**********@kctdata.cz
might have written:
thanks a lot for this solution.
Next thing: how may i find out that that address is multicast one? is
there some easy possibility or i have to use regex now?


To quote a Google reply:

"IPv6 multicast addresses are distinguished from unicast addresses by the
value of the high-order octet of the addresses: a value of 0xFF (binary
11111111) identifies an address as a multicast address; any other value
identifies an address as a unicast address."
--
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
Apr 2 '06 #4

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

Similar topics

0
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
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
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...
2
by: PaulH | last post by:
I am attempting to write a functon that can perform IPv6 compliant pings. But, Icmp6SendEcho2 causes an access violation whenever it is called: First-chance exception at 0x76d641e8 in mping2.exe:...
2
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...
8
by: prabhuram.k | last post by:
Can anybody know how to validate IPV4 and IPV6 address in C++
3
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...
8
by: Giampaolo Rodola' | last post by:
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...
14
by: Simon | last post by:
Hi, is there a straight forward way of converting IPv4 to IPv6? I thought that it was just a matter of converting 32 bits to 128 bits, (by adding 96 leading 0s), but that does not seem right...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.