This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Testing if a IP is valid

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Testing if a IP is valid

Post by ComputerTech »

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
User avatar
CrazyCat
Revered One
Posts: 1251
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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: Select all

% 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.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Awesome! Thanks very much caesar :D

And thanks CrazyCat for the link you provided as well :)
ComputerTech
Post Reply