谁能用shell脚本帮我写段代码 谢谢
-
- 帖子: 39
- 注册时间: 2009-01-01 14:06
谁能用shell脚本帮我写段代码 谢谢
思路:每60秒通过 http://www.ip.cn/ 这个网站查询本机ip 如果ip改变就执行一段命令 程序要循环运行
- 麦斯特
- 帖子: 1034
- 注册时间: 2005-03-28 0:00
- 系统: Gentoo x64
- 来自: ☸我佛山人
Re: 谁能用shell脚本帮我写段代码 谢谢
我的想法是先弄个循环,sleep 60然后用sed获取ifconfig那几个关键词的输出,跟上一次获得的结果进行比照,假如结果不同就进行处理,想也不是很难。
Je ne suis pas d'accord avec ce que vous dites, mais je me battrai jusqu'à la mort pour que vous ayez le droit de le dire.
-
- 帖子: 39
- 注册时间: 2009-01-01 14:06
Re: 谁能用shell脚本帮我写段代码 谢谢
帮我写一下吧 我是小白不懂麦斯特 写了:我的想法是先弄个循环,sleep 60然后用sed获取ifconfig那几个关键词的输出,跟上一次获得的结果进行比照,假如结果不同就进行处理,想也不是很难。
你看下这个帖子 最好从网站获取ip http://icanhazip.com/ 用这个网站获取ip容易点
http://forum.ubuntu.org.cn/viewtopic.php?f=21&t=374618
- 麦斯特
- 帖子: 1034
- 注册时间: 2005-03-28 0:00
- 系统: Gentoo x64
- 来自: ☸我佛山人
Re: 谁能用shell脚本帮我写段代码 谢谢
现在的环境不方便……
Je ne suis pas d'accord avec ce que vous dites, mais je me battrai jusqu'à la mort pour que vous ayez le droit de le dire.
-
- 帖子: 39
- 注册时间: 2009-01-01 14:06
Re: 谁能用shell脚本帮我写段代码 谢谢
有时间帮我写下 好不麦斯特 写了:现在的环境不方便……
-
- 帖子: 22323
- 注册时间: 2010-07-19 21:41
- 系统: OS X
-
- 帖子: 22323
- 注册时间: 2010-07-19 21:41
- 系统: OS X
- 麦斯特
- 帖子: 1034
- 注册时间: 2005-03-28 0:00
- 系统: Gentoo x64
- 来自: ☸我佛山人
Re: 谁能用shell脚本帮我写段代码 谢谢
记得之前YeLee写过一个网路监视的脚本,你去搜一下吧。
Je ne suis pas d'accord avec ce que vous dites, mais je me battrai jusqu'à la mort pour que vous ayez le droit de le dire.
-
- 帖子: 39
- 注册时间: 2009-01-01 14:06
- 枫叶饭团
- 帖子: 14683
- 注册时间: 2010-06-16 1:05
- 系统: Mac OS X
- 来自: Tencent
- 联系:
Re: 谁能用shell脚本帮我写段代码 谢谢
代码: 全选
^_^[maplebeats@acer-5750G:~/Works/test]$ python3 ip.py
123.145.97.29
123.145.97.29
123.145.97.29
^CTraceback (most recent call last):
File "ip.py", line 9, in <module>
time.sleep(2)
KeyboardInterrupt
QAQ[maplebeats@acer-5750G:~/Works/test]$ vi ip.py
^_^[maplebeats@acer-5750G:~/Works/test]$ cat ip.py
#/usr/bin/env python3
import urllib.request as ur
import re,time
while True:
fp = ur.urlopen("http://icanhazip.com")
ip=re.compile(r'[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')
text = fp.read().decode("utf8")
print(ip.findall(text)[0])
time.sleep(60)
^_^[maplebeats@acer-5750G:~/Works/test]$
- 枫叶饭团
- 帖子: 14683
- 注册时间: 2010-06-16 1:05
- 系统: Mac OS X
- 来自: Tencent
- 联系:
Re: 谁能用shell脚本帮我写段代码 谢谢
写了个很搞笑的正则



- 枫叶饭团
- 帖子: 14683
- 注册时间: 2010-06-16 1:05
- 系统: Mac OS X
- 来自: Tencent
- 联系:
Re: 谁能用shell脚本帮我写段代码 谢谢
我错了,还要判断啊
- 枫叶饭团
- 帖子: 14683
- 注册时间: 2010-06-16 1:05
- 系统: Mac OS X
- 来自: Tencent
- 联系:
Re: 谁能用shell脚本帮我写段代码 谢谢
[python]
#/usr/bin/env python3
import urllib.request as ur
import re,time
def getip():
fp =ur.urlopen("http://icanhazip.com")
ip = re.compile(r'[\d\.]*')
return ip.findall(fp.read().decode("utf8"))[0]
temp = getip()
while True:
myip = getip()
if myip != temp:
print(myip) #do
temp = getip()
print(myip)
time.sleep(60)
[/python]
#/usr/bin/env python3
import urllib.request as ur
import re,time
def getip():
fp =ur.urlopen("http://icanhazip.com")
ip = re.compile(r'[\d\.]*')
return ip.findall(fp.read().decode("utf8"))[0]
temp = getip()
while True:
myip = getip()
if myip != temp:
print(myip) #do
temp = getip()
print(myip)
time.sleep(60)
[/python]
- YeLee
- 论坛版主
- 帖子: 26406
- 注册时间: 2008-08-13 8:48
- 系统: Fundu i64
- 来自: 东海硇州,一双管钥。
- 联系:
Re: 谁能用shell脚本帮我写段代码 谢谢
楼上给力啊,菜鸟学习了。




◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
- ptpt52
- 帖子: 717
- 注册时间: 2008-07-27 8:51
- 系统: Ubuntu/Windows
- 来自: 广西玉林|广东深圳
- 联系:
Re: 谁能用shell脚本帮我写段代码 谢谢
代码: 全选
#!/bin/bash
myip=`wget http://www.ip138.com/ip2city.asp -O - 2>/dev/null | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'`
while :; do
sleep 60
newip=`wget http://www.ip138.com/ip2city.asp -O - 2>/dev/null | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'`
[ ! "x$myip" = "x$newip" ] && {
#do your jop
myip=$newip
}
done
走过去了也便有了路
http://www.ptpt52.com/
http://www.ptpt52.com/