Jump to content


Photo
- - - - -

Validate IPv4 and IPv6 adresses


  • Please log in to reply
1 reply to this topic

#1 Wouter

Wouter

    Very Active

  • Members
  • PipPipPip
  • 103 posts
  • Version:LabVIEW 2011
  • Since:2006

Posted 04 January 2012 - 02:00 AM

VI Name:
IP Validation

Total VIs:
strpos.vi, strrpos.vi, substr_count.vi, valid_ipv6.vi, test,vi, unittest.vi, ip2long.vi, long2ip.vi, valid_ipv4.vi

Description:
I saw in the svn of OpenG that there was a candidate for IP validation. But however I think I have a better one. One for IPv4 and one for IPv6, credits for the IPv6 algo goes to http://crisp.tweakbl...d-caveats).html

Note:
-

Blockdiagram:
-

What are you thoughts on this VI?
  • Would you like to see such a function in OpenG?
  • Can you optimize the code?
  • In which package should it be included?
  • Should it be rejected?

-edit- ups I forgot to set the unittests data I inputed in the control as default value... well you can now enter them by hand.
$unitTests = array(
    '2001:0db8:0000:0000:0000:0000:1428:57ab'    => true,
    '2001:0DB8:0000:0000:0000:0000:1428:57AB'    => true,
    '2001:00db8:0000:0000:0000:0000:1428:57ab'    => false,
    '2001:0db8:xxxx:0000:0000:0000:1428:57ab'    => false,

    '2001:db8::1428:57ab'    => true,
    '2001:db8::1428::57ab'    => false,
    '2001:dx0::1234'    => false,
    '2001:db0::12345'    => false,

    ''            => false,
    ':'            => false,
    '::'            => true,
    ':::'            => false,
    '::::'            => false,
    '::1'            => true,
    ':::1'            => false,

    '::1.2.3.4'        => true,
    '::256.0.0.1'        => false,
    '::01.02.03.04'        => false,
    'a:b:c::1.2.3.4'    => true,
    'a:b:c:d::1.2.3.4'    => true,
    'a:b:c:d:e::1.2.3.4'    => true,
    'a:b:c:d:e:f:1.2.3.4'    => true,
    'a:b:c:d:e:f:1.256.3.4'    => false,
    'a:b:c:d:e:f::1.2.3.4'    => false,

    'a:b:c:d:e:f:0:1:2'    => false,
    'a:b:c:d:e:f:0:1'    => true,
    'a::b:c:d:e:f:0:1'    => false,
    'a::c:d:e:f:0:1'    => true,
    'a:<img src='http://lavag.org/public/style_emoticons/<#EMO_DIR#>/biggrin.png' class='bbc_emoticon' alt=':D' />:e:f:0:1'        => true,
    'a::e:f:0:1'        => true,
    'a::f:0:1'        => true,
    'a::0:1'        => true,
    'a::1'            => true,
    'a::'            => true,

    '::0:1:a:b:c:d:e:f'    => false,
    '::0:a:b:c:d:e:f'    => false,
    '::a:b:c:d:e:f'        => true,
    '::b:c:d:e:f'        => true,
    '::c:d:e:f'        => true,
    ':<img src='http://lavag.org/public/style_emoticons/<#EMO_DIR#>/biggrin.png' class='bbc_emoticon' alt=':D' />:e:f'        => true,
    '::e:f'            => true,
    '::f'            => true,

    '0:1:a:b:c:d:e:f::'    => false,
    '0:a:b:c:d:e:f::'    => false,
    'a:b:c:d:e:f::'        => true,
    'b:c:d:e:f::'        => true,
    'c:d:e:f::'        => true,
    'd:e:f::'        => true,
    'e:f::'            => true,
    'f::'            => true,

    'a:b:::e:f'        => false,
    '::a:'            => false,
    '::a::'            => false,
    ':a::b'            => false,
    'a::b:'            => false,
    '::a:b::c'        => false,
    'abcde::f'        => false,

    '10.0.0.1'        => false,
    ':10.0.0.1'        => false,
    '0:0:0:255.255.255.255'    => false,
    '1fff::a88:85a3::172.31.128.1' => false,

    'a:b:c:d:e:f:0::1'    => false,
    'a:b:c:d:e:f:0::'    => false,
    'a:b:c:d:e:f::0'    => true,
    'a:b:c:d:e:f::'        => true,

    'total gibberish'    => false

);

Attached Files


Edited by Wouter, 04 January 2012 - 02:05 AM.


#2 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 04 January 2012 - 03:35 PM

Having only gleaned a little from the VIs names, I presume it uses string/token-based analysis to validate the strings as an IP address. There exists the the "String to IP" and "IP to String" LabVIEW nodes, I wonder if these would be faster to use for IPv4 addresses? There may be OS-specific calls which are faster,

In general, though, I think that these would be helpful only in data validation scenarios, rather than actual networking scenarios - if you plug in an ill-formed address, the networking node will return the correct error and you should handle it downstream.

Also, your IPv6 reference link got mangled.