Linux 版 (精华区)
发信人: howdoit (教练让我上场!!!), 信区: Linux
标 题: 从PPP启动脚本得到动态分配的IP地址
发信站: 哈工大紫丁香 (Tue May 18 08:39:23 1999), 转信
《Linux公报》……让Linux更富魅力!
The Answer Guy
By James T. Dennis, answerguy@ssc.com
Starshine Technical Services, http://www.starshine.org/
翻译: gaia
从PPP启动脚本得到动态分配的IP地址
>From D. Kim Croft on Tue, 17 Nov 1998
我想做一个脚本,让它在我拨号上网时,把一个链接到我的IP地址的小
HTML文件
上载到我的WEB帐号.但由于我的IP地址是动态分配的,我没法确切知道
它是什么.在
windows下我可以用netstat -rn找到,但在Linux下,当我用netstat
-rn时只得到了
我的?路由器?.总而言之不知你是否知道什么办法能让我在连线后找到
IP地址.十
分感谢.
我们假设你用Linux的pppd软件包建立拨号连接.要是这样,最
显而易见的办法就是
从'/etc/ppp/ip-up'脚本中调用你的脚本.看看'pppd'的帮助手册我们
能找到很多
地方提到这个文件,它是在PPP会话已建立时被自动调
用.('/etc/ppp/ip-down'是在
会话终止时被调用.)
调用ip-up时有5个参数被传送给它:
interface名 设备 速率 你的IP 对方IP
...此外pppd的一个选项允许你指定一个额外的参数,你可以在你的
option文件里设
置它.
所以你可以让你的脚本取得你需要的参数(这里只需要你的IP地址),在
你的ip-up里
用以下命令行调用你的脚本:
/usr/local/bin/update-my-web-page $4
...其中'update-my-web-page'可以是shell, perl, awk, Python,
TCL或其它脚本
或程序,打开到你的WEB站点主机的连接并把那个HTML文件写上去(假设
你有
'rcp/rsh', ksh (Kerberos 'rsh') 'ssh/scp'或C-kermit或
'expect/ftp'连接及
传输脚本,可以自动发送文件.)
Using A Dynamically Assigned Address from PPP
Startup Script
From D. Kim Croft on Tue, 17 Nov 1998
I am trying to set up a script that, when I connect to the internet will wr
ite alittle html file with a link to my ipaddress to upload to my web accou
nt onmy isp. However my ip address is dynammically assigned so I never know
exactly what it is. In windows I can netstat -rn to find it but,in linux wh
en Inetstat -rn i only get my ?router?. Anyways If you know of any way that
Ican find my ipaddress when I connect. it would be greatly apprecciated.
Let's assume that you are using the Linux
pppd package to establish this connection. In that
case the most obvious method would be to call your
script from the '/etc/ppp/ip-up' script. Reading the
'pppd' man page we find a couple of references to
this file, which is automagically called when the
PPP session is established. ('/etc/ppp/ip-down' is
called when the session is terminated).
It's called with five parameters including:
interface device speed your-IP their-IP
.. and there's an option to provide an additional,
admin specified parameter which can be set from
your options file.
So you can write your script to just take the
parameters you need (just the local IP address in
this case) can call it with an entry in your ip-up
script with a command like:
/usr/local/bin/update-my-web-page $4
... where 'update-my-web-page' is a shell, perl,
awk, Python, TCL, or other script or program that
opens a connection to your website's host and
writes your page to it. (I'll assume that you have
'rcp/rsh', ksh (Kerberos 'rsh') 'ssh/scp' or C-kermit
or 'expect/ftp' connect and tranfer script that can
automate the file propagation process.
thankyou
版权所有 (C) 1998 NJLUG
出版于第35期《Linux公报》1998年12月 中文版第二期
rpm
passwd
links
ipscript
magickeys
--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: bin@mtlab.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.461毫秒