BASH IP地址检查 [英] BASH IP Address Check

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

问题描述

我工作的一个bash shell脚本,我需要能够检查,看看如果IP地址从返回:

I am working on a BASH shell script where I need to be able to check and see if the IP address returned from:

dig $HOSTNAME +short

是一个特定的子网或不在。例如,如果192.168.10.x或10.130.10.x部分然后再做别的ž做年。

is within a particular subnet or not. For example, if part of 192.168.10.x or 10.130.10.x then do z else do y.

我不知道如何操作或检查IP地址后,我把它保存在一个变量,这样我可以打造出上述的逻辑测试。

I am not sure how to manipulate or check the IP address after I have it stored in a variable so that I can build out the logical test described above.

推荐答案

我最终使用以下code,使其工作:

I ended up using the following code to make it work:

if [[ "$IP" == *10.130.10.* || "$IP" == *192.168.10.* ]]; then
   mount code goes here
fi

感谢大家的帮助和解释的事情对我来说,让我进一步了解脚本。这实在是AP preciated!

Thanks for everyone's help and explaining things to me to allow me to further learn about scripting. It is really appreciated!

这篇关于BASH IP地址检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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