LabVIEW Development Best Practices Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

IP Validation

Dear All Engineers,

You can validate user input IP address using the attached VI.

Thanks and Regards
Himanshu Goyal | LabVIEW Engineer- Power System Automation
Values that steer us ahead: Passion | Innovation | Ambition | Diligence | Teamwork
It Only gets BETTER!!!
Thanks and Regards
Himanshu Goyal | LabVIEW Engineer- Power System Automation
Values that steer us ahead: Passion | Innovation | Ambition | Diligence | Teamwork
It Only gets BETTER!!!
Download All
Comments
mini09
Active Participant
Active Participant
on

Can I`ve in LV11

LuI
Active Participant
Active Participant
on

Well,

in a limited way one can.

But your intention is ambiguous IMHO. It only accepts IP adresses in dot notation (1.2.3.4) on my system. If I provide a valid machine name ('pc1234') that can be resolved here, it returns 'Invalid'. Allthough the 'String to IP'-node returns a valid IP adress, but the 'IP to String'-node changes that to an IP in dot notation. And even if one changes that nodes control 'dot notation?' to false, it returns the complete machine name including the domain name (pc1234.mydomain.local) etc., which is not completely EQUAL to what was typed in. 

You should deside what you want to achieve, e.g. test for a well-defined adress or for an adress that could be resolved or whatever.

Just my € 0.02!

Greetings from Germany!

--

LuI

lcgswolf
Member
Member
on

Hello Everyone, I used the proposed solution above but I faced an unexpected issue, if the input value is an invalid IP Address (e.g. "42" or "hello") the VI take at least 2000 ms to execute, therefore I have to do it manually for a faster validation, the attached image shows my solution.

 

Check IP.PNG

It takes minimum execution time for almost any input value



 

JohnatanBravo
Member
Member
on

I know this thread is a bit dated, I will still add my 5 cents...

 

@lcgswolf

You're right, OP's solution (while very elegant and simple) causes a bit of a delay (2.7 sec in my case) if the input is a single string.

 

Your solution works, but doesn't detect non numeric characters. So something like this will pass: a.b.c.d , 1.2.3.a, 1.2.3.

 

I added some changes to fix those issues (can't attach a Vi, but this is easy to copy):

Screenshot 2024-05-21 103257.png

 

 

 

Also, I think the above solution is a bit complicated...

The way I do it in my programs, uses a "simple" regex check, there are no delays and I haven't been able to fault it yet.

The for loop makes sure we don't have 0.0.0.0 situation, which is not a valid IP address:

JohnatanBravo_0-1736254399388.png

 

 

Regex: \b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b

 

Edit:

This response was edited after some shortcomings of the originally proposed regex string were found

Original string was: \b((([0-2]\d[0-5])|(\d{2})|(\d))\.){3}(([0-2]\d[0-5])|(\d{2})|(\d))\b

 

The below string from @ThinkG works well also.

 

ThinkG
Member
Member
on

Love the regex approach! I don't understand regex well enough, but 192.168.88.101 fails to validate with the regex given above.

 

The following regex posted on stackoverflow by mousio works with 192.168.88.101.

 

Regex: \b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b

JohnatanBravo
Member
Member
on

Hi ThinkG,

 

Yeah I had noticed the shortcomings of the above regex string since I posted that response.

I changed it to the following in my own code:

 

\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b

 

I've forgotten I shared it here... Otherwise I would have came back and added an edit.

 

Thanks!

Contributors