dns设置网关地址(dns和默认网关)
- lua脚本还有一个好用的功能,就是单独使用的脚本。相比壳牌,会好看一些。特别是有很强的字符串处理,C基础很好理解。app={}
App.ip = "192.168.8.156" -这里的目标ip,网关和DNS都配置了相同的IP。
app.dns_file = "/etc/resolv.conf "
函数dns_is_ok(ip,文件)
local f = io.open(文件,“r”)
如果f ==零,那么
返回零
结束
local txt = f:read("*all ")
local dest_dns = string.format("名称服务器%s ",ip)
f:关闭()
打印(" dns_is_ok ")
打印(文本)
pos = string.find(txt,dest_dns,1)
退货位置
结束
功能集_网络(ip)
local del _ cmd = string . format(" route del default ")
local dest _ cmd = string . format(" route add default GW % s ",ip)
local DNS _ set _ cmd = string . format(" echo"名称服务器% s"gt%s ",ip,app.dns_file)
打印(del_cmd)
os.execute(del_cmd)
打印(目标命令)
os.execute(目标命令)
local pos = dns_is_ok(ip,app.dns_file)
如果位置= =零,则
打印("设置dns "..ip)
os.execute(dns_set_cmd)
结束
结束
set_network(app.ip)
页:
[1]