INi文件转换的问题,请高手帮忙
本帖最后由 58fly 于 2010-4-9 21:29 编辑192.168.0.254=00-00-4f-67-00-d4
192.168.0.4=00-26-18-DF-46-55
192.168.0.5=00-26-18-DD-D9-EE
192.168.0.9=00-26-18-DD-DB-A2
192.168.0.10=00-26-18-DF-46-BE
192.168.0.11=00-26-18-DF-46-85
192.168.0.12=00-26-18-DF-44-D1
更改后:
192.168.0.1=00-00-00-00-00-00
192.168.0.2=00-00-00-00-00-00
192.168.0.3=00-00-00-00-00-00
192.168.0.4=00-26-18-DF-46-55
192.168.0.5=00-26-18-DD-D9-EE
192.168.0.6=00-00-00-00-00-00
192.168.0.7=00-00-00-00-00-00
192.168.0.8=00-00-00-00-00-00
192.168.0.9=00-26-18-DD-DB-A2
192.168.0.10=00-26-18-DF-46-BE
192.168.0.11=00-26-18-DF-46-85
192.168.0.12=00-26-18-DF-44-D1
192.168.0.13=00-00-00-00-00-00
.....
192.168.0.253=00-00-00-00-00-00
192.168.0.254=00-00-4f-67-00-d4
实际功能就是IP地址排序,然后没有的自动补充,并设置MAC为0000000000原始的:
192.168.0.254=00-00-4f-67-00-d4
192.168.0.4=00-26-18-DF-46-55
192.168.0.5=00-26-18- ...
58fly 发表于 2010-4-9 21:23 http://www.autoitx.com/images/common/back.gif
没有的自动补充--- 你更改后的也没见补充完整吧 .2.3.6 ... afan那个问题我写的仓促,实际是自动补充的意思,我改一下,帮我看看 For $i = 1 To 254
$s = IniRead('ipmac.ini', 'MAC绑定模块', '192.168.0.' & $i, '00-00-00-00-00-00')
IniWrite('new.ini', 'MAC绑定模块', '192.168.0.' & $i, $s)
Next转化原来的ipmac.ini为new.ini $s = IniRead('ipmac.ini', 'MAC绑定模块', '192.168.0.' & $i, '00-00-00-00-00-00')还真的从来没这么用过..厉害 Opt("MustDeclareVars", 1)
#include <Array.au3>
Global Const $sSrcIni = @ScriptDir & "\ipmac.ini", $sTarIni = @ScriptDir & "\new.ini"
If NOT FileExists($sSrcIni) Then Exit 1
ConvMAC()
Exit
Func ConvMAC()
Local $aOldMAC, $aNewMAC, $sIPPre3, $iElement
$aOldMAC = IniReadSection($sSrcIni, "MAC绑定模块")
If $aOldMAC < 1 Then Return SetError(1, 0, 0)
If NOT StringRegExp($aOldMAC, "^((25|2\d|?\d?\d)\.){3}(25|2\d|?\d?\d)$") Then Return SetError(1, 0, 0)
$sIPPre3 = StringLeft($aOldMAC, StringInStr($aOldMAC, ".", 0, -1))
For $i = 1 To 255
$aNewMAC[$i] = $sIPPre3 & $i
$iElement = _ArraySearch($aOldMAC, $aNewMAC[$i], 1)
If @error Then
$aNewMAC[$i] = "00-00-00-00-00-00"
Else
$aNewMAC[$i] = StringUpper($aOldMAC[$iElement])
EndIf
Next
IniWriteSection($sTarIni, "MAC绑定模块", $aNewMAC, 1)
Return
EndFunc ;==>ConvMAC 转化原来的ipmac.ini为new.ini
nmgwddj 发表于 2010-4-9 21:59 http://www.autoitx.com/images/common/back.gif
这样应该会有不少耗时的I/O操作,改用以下写法可以快20倍左右,数据量越大差距将越大。Local $out, $i, $s
For $i = 1 To 254
$s = IniRead('1.ini', 'MAC绑定模块', '192.168.0.' & $i, '00-00-00-00-00-00')
$out &= '192.168.0.' & $i & '=' & $s & @LF
Next
IniWriteSection('New.ini', 'MAC绑定模块', $out) 方法如此之多 看来还是要学习啊 $out &= '192.168.0.' & $i & '=' & $s & @LF
这句太精彩了,节省不少系统资源
页:
[1]