473,772 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6245
In article <11************ **********@g10g 2000cwb.googleg roups.com>,
ji**********@kc tdata.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_pto n(). 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_pto n(socket.AF_INE T6, "8001::1244 ") '\x80\x01\x00\x 00\x00\x00\x00\ x00\x00\x00\x00 \x00\x00\x00\x1 2D' socket.inet_pto n(socket.AF_INE T6, "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**********@kc tdata.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
1795
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 participate in transitioning to the new Internet is in response to both DoD and Industry requests for a concentrated, affordable conference in the Washington, D.C. area. This exciting and informative conference on the Next Generation Internet will...
7
5951
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 two computers are connected in an IPv6-network. No matter if I give the hostname (defined in /etc/hosts), the IPv6-address ("fec0::4") or the IPv6-address in square brackets ("") the function mysql_connect always prints "Unknown MYSQL-Server "....
8
2543
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 that if I create the listening socket with sock = socket(AF_INET, SOCK_STREAM) it will accept connections on ipv4 (only) and if I create it with sock = socket(AF_INET6, SOCK_STREAM) it will accept connections with ipv6 (only)
2
6393
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: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x76d641e8 in mping2.exe: 0xC0000005: Access violation reading location 0x00000000. I have been unable to pinpoint the cause of the access violation so far, so I...
2
3026
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 http://www.codeproject.com/csharp/ipv6.asp I am developing an application where I need to broadcast information to clients. I have hit a 64K limit in UDP broadcasting. I am not exited
8
9942
by: prabhuram.k | last post by:
Can anybody know how to validate IPV4 and IPV6 address in C++
3
1858
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 it support tunneling of IPv6 on a IPv4 network? 4. If an IPv4 address is given, does it support this on a IPv6 network? If not can you kindly let me know, Are there any plans for supporting these features in future?
8
8948
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 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...
14
9297
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 in some/most cases. For example, 127.0.0.1, (IPv4 localhost), does not convert ::1, (IPv6 localhost)
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9911
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.