使用 tcl 验证 ip 地址 [英] Validation of ip-address using tcl

查看:36
本文介绍了使用 tcl 验证 ip 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好frnds m 在这个程序中遇到了问题..cn 任何告诉我我哪里出错了??无法验证 255.255.255.255 ip 地址

Hello frnds m facing problem in this program..cn any tell me where m i making mistake?? m nt able to validate for 255.255.255.255 ip address

puts "Enter a valid ip address:"
set string [gets stdin]
if {[regexp {^([1-9]|[1]\d{2}|[2][0-4]\d|25[0-5])((\.\d{0,2}|1\d{2}|2[0-4]\d|25[0-5]){3})$} $string match]} {
    puts $string
} else {
    puts "INVALID-ADDRESS"
}

推荐答案

不要重新发明轮子.有许多关于如何验证 IP 地址的工作示例.在这里查看一些http://wiki.tcl.tk/989

Don't reinvent the wheel. There are dozens of working examples of how to validate IP addresses. See here for some http://wiki.tcl.tk/989

此外,如果您有 TCLlib,您可以使用 ::ip::version 命令,例如

Also if you have TCLlib you can use the ::ip::version command e.g

% package require ip
1.2
% ::ip::version 192.168.0.1
4
% ::ip::version www.google.com
-1
% ::ip::version 192.168.0.333
-1

这篇关于使用 tcl 验证 ip 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆