找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 5223|回复: 2

[脚本] 本帖提供一个将ip分段成4段提取的范例

[复制链接]
发表于 2013-11-17 20:55:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
本帖提供一个将ip分段成4段提取的范例,方法比较笨拙(若哪位有更佳方法,可随帖)。案例仅仅是一个思路,会用的人可以在实际应用中去修改使用。
:local ip  1.22.333.4444/32
:local section1  
:local section2
:local section3  
:local section4

:local length
:local length1  
:local length2
:local length3  
:local length4   

:set ip [:pick $ip 0 [:find  $ip "/"]]
:set length [:len $ip]
:log warn $ip


########section1#########
:set section1 [:pick $ip 0 [:find  $ip "."]]
:set length1  [:len $section1]
:log warn     ("ip_section1 is: " . $section1 . "   length is: " . $length1)

########section2#########
:set section2 [:pick $ip ($length1+1) $length]
:set section2 [:pick $section2 0 [:find  $section2 "."]]
:set length2  [:len $section2]
:log warn     ("ip_section2 is: " . $section2 . "   length is: " . $length2)

########section3#########
:set section3 [:pick $ip ($length1+1+$length2+1) $length]
:set section3 [:pick $section3 0 [:find  $section3 "."]]
:set length3  [:len $section3]
:log warn     ("ip_section3 is: " . $section3 . "   length is: " . $length3)

########section4#########
:set section4 [:pick $ip ($length1+1+$length2+1+$length3+1) $length]
:set length4  [:len $section4]
:log warn     ("ip_section4 is: " . $section4 . "   length is: " . $length4)

评分

参与人数 1铜板 +30 收起 理由
9939781 + 30 支持原创

查看全部评分

routeros
发表于 2013-11-17 21:10:00 | 显示全部楼层
我也是这个办法,根据点位提取各段ip值

不过楼主比我写的脚本更规范
routeros
回复

使用道具 举报

 楼主| 发表于 2013-11-17 21:18:39 | 显示全部楼层
谢谢山东兄弟sealin ,从你那里购买的你的dell服务器,我还在用呢,你最近新增什么高配置的硬件了??
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-5-18 04:05 , Processed in 0.047755 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表