Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编写bash脚本以读取、比较和验证外部IP地址。需要帮助吗_Bash - Fatal编程技术网

编写bash脚本以读取、比较和验证外部IP地址。需要帮助吗

编写bash脚本以读取、比较和验证外部IP地址。需要帮助吗,bash,Bash,我是bash新手,在编写一个简单的脚本以查看调用脚本的服务器是否是我想要执行脚本的服务器时遇到了困难。获取外部IP很容易,并且有很多其他关于它的帖子。不过,我对IF语句有问题 #!/bin/bash if [ wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' -ne '174.123.248.82' ] ; then echo "matches"; fi 谢谢 试试这个: #

我是bash新手,在编写一个简单的脚本以查看调用脚本的服务器是否是我想要执行脚本的服务器时遇到了困难。获取外部IP很容易,并且有很多其他关于它的帖子。不过,我对IF语句有问题

#!/bin/bash
if [ wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' -ne '174.123.248.82' ] ; then echo "matches"; fi
谢谢

试试这个:

#!/bin/bash
if [ `wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'` != '174.123.248.82' ] ; then echo "matches"; fi
#/bin/bash

if[`wget-q-O-checkip.dyndns.org | sed-e's/*当前IP地址://'-e's/在脚本中,if命令在|处中断。如下更改

if [ $(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//') != '174.123.248.82' ] ; then 
   echo "matches"; 
fi
if[$(wget-q-O-checkip.dyndns.org | sed-e's/*当前IP地址:/'-e's/使用shell执行此操作

check="174.123.248.82"
result=$(wget -q -O - checkip.dyndns.org)
ip=${result//[^0-9.]/}
[[ "$ip" != "$check" ]] && echo "matches"

谢谢大家。这非常有效,我在这个过程中学会了一些bash。
check="174.123.248.82"
result=$(wget -q -O - checkip.dyndns.org)
ip=${result//[^0-9.]/}
[[ "$ip" != "$check" ]] && echo "matches"