博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
check MAC Address Validation
阅读量:4285 次
发布时间:2019-05-27

本文共 739 字,大约阅读时间需要 2 分钟。

轉載自

MAC Address Validation Regex with egrep

I needed an easy way to validate a MAC address in a bash script that generated a unique hostname based on the MAC address of the system. This gem did the trick:

[code lang=”bash”]
echo "00:11:24:3e:a5:78" | egrep "^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"
[/code]

In the event that there was a problem getting the MAC address (e.g., faulty NIC or unstable device driver), I generate a random hostname instead of basing the hostname generation on the MAC. Here’s how I validated the MAC in the script:

[code lang=”bash”]
if [ echo $ACTIVE_INTERFACE_MAC | egrep "^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$" ]; then
# generate unique hostname based on MAC
else
# generate random-character hostname
fi
[/code]

转载地址:http://chsgi.baihongyu.com/

你可能感兴趣的文章
"未能加载文件或程序集“MySql.Data, Version=6.9.3.0”或它的某一个依赖项。
查看>>
CodeFirst for MySql
查看>>
Code Frist for Mysql 实例
查看>>
Visual Studio 开源控件扩展 NuGet 常用命令及常用组件
查看>>
mysql局域网访问设置
查看>>
UEditor 编辑器跨域上传解决方法
查看>>
VisualSVN Server搭建SVN服务器
查看>>
AngularJs directive指令详解
查看>>
AngularJs directive-scope
查看>>
AngularJs directive-link实例
查看>>
Js实现Base64编码、解码
查看>>
AngularJs directive-scope双向绑定方法处理-实例2
查看>>
AngularJs Ajax分页控件
查看>>
LocalDB数据库修改排序规则,修复汉字变问号
查看>>
C# Json序列化工具--Newtonsoft.Json简介和使用
查看>>
EntityFramework中Json序列化的循环引用问题解决--Newtonsoft.Json
查看>>
AngularJs----ng-class
查看>>
Bootstrap3 datetimepicker控件的使用
查看>>
NodeJs常用链接整理
查看>>
Bootstrap model的使用及点击外部不消失
查看>>