| View previous topic :: View next topic |
| Author |
Message |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Mon Jun 28, 2021 6:31 pm Post subject: Testing if a IP is valid |
|
|
So i am trying to find a code that will check if a IP has the correct syntax of a IPv4 or IPv6 IP, i have no idea how that would look, but all help is much appreciated  _________________ ComputerTech |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Jun 29, 2021 3:01 am Post subject: |
|
|
Here's a better link with Regular Expression Examples.
If you don't want to fiddle with regexp and basically reinvent the wheel, then use the ip package that comes with TCLlib that offers some tools to validate ipv4 or ipv6, like:
| Code: |
% package require ip
1.4
::ip::version 192.168.0.1
1
% ::ip::version 192.168.0.256
-1
% ::ip::is ipv4 192.168.0.1
1
% ::ip::version 192.198.0.256
-1
% ::ip::version 2001:bc8:32d7:26c::
6
|
You can find the source code of a previous version here (or if you are on Debian you should find it in /usr/share/tcltk/tcllib1.20/dns/ip.tcl, if not do a locate ip.tcl) to see what other commands are available. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Tue Jun 29, 2021 9:06 am Post subject: |
|
|
Awesome! Thanks very much caesar
And thanks CrazyCat for the link you provided as well  _________________ ComputerTech |
|
| Back to top |
|
 |
|