找回密码
 加入
搜索
查看: 3553|回复: 6

[系统综合] 〈已解决〉读取网关并作出判断动作,跪求大神阿

  [复制链接]
发表于 2015-9-17 09:52:22 | 显示全部楼层 |阅读模式
本帖最后由 哈喽IT 于 2015-9-19 14:17 编辑

条件:
分A,B两个办公区域,
A区网关172.1.1.1 ,172.1.2.1,172.1.3.1
B区网关172.1.6.1 ,172.1.7.1,172.1.8.1

我想通过获取到 A ,B区的网关,作出判断语句

需求:
获取到A区网关 “172.1.1.1”,那么条件真,执行安装1
如果网关非 “172.1.1.1”,  msgbox("xxx","区域错误无法安装")
发表于 2015-9-17 21:00:03 | 显示全部楼层
回复 1# 哈喽IT
有两个获取网络参数的函数,前一个" _ipconfig"适合XP系统,后一个" _ipconfig_"适合WIN7.
Local $sText = _ipconfig_()
Local $sGateWay = '172.1.1.1'
If StringInStr($sText, $sGateWay) Then
        MsgBox(0, 'msg', '区域符合,可以安装。')
Else
        msgbox(16, 'msg','区域错误,无法安装!')
EndIf
 

Func _ipconfig()
        Local $iPID, $sText = ''
        $iPID = Run(@ComSpec & " /c ipconfig", '', @SW_HIDE, 6)
        While 1
                $sText &= StdoutRead($iPID)
                If @error Then ExitLoop
        WEnd
Return $sText
EndFunc

Func _ipconfig_()
        Local $iPID, $sText = ''
        $iPID = Run(@ComSpec & " /c ipconfig", '', @SW_HIDE, 6)
        ProcessWaitClose($iPID)
        $sText = StdoutRead($iPID)
Return $sText
EndFunc
 楼主| 发表于 2015-9-18 08:45:01 | 显示全部楼层
回复 2# Alam


   谢谢您,我这就去试试。
 楼主| 发表于 2015-9-18 09:19:04 | 显示全部楼层
回复 2# Alam


    你好大致框架已经OK了,

可是好像无法抓取到本机网关比对阿    一直提示的是区域错误这句
发表于 2015-9-18 20:09:50 | 显示全部楼层
在你的网络环境下自己调试吧。
Local $sText = _ipconfig()
ConsoleWrite($sText & @CRLF)
Local $sGateWay = '172.1.1.1'
If StringInStr($sText, $sGateWay) Then
        MsgBox(0, 'msg', '区域符合,可以安装。')
Else
        msgbox(16, 'msg','区域错误,无法安装!')
EndIf 

Func _ipconfig()
    Local $sFile = StringReplace(@TempDir & '\_ip.txt', '\\', '\')
        Local $sText
        RunWait(@ComSpec & " /c ipconfig > " & $sFile, '', @SW_HIDE)
        $sText = FileRead($sFile)
        FileDelete($sFile)
Return $sText
EndFunc
发表于 2015-9-18 23:38:21 | 显示全部楼层
试试使用正则...
 楼主| 发表于 2015-9-19 14:19:45 | 显示全部楼层
回复 5# Alam


   非常感谢,OKle
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 20:10 , Processed in 0.138453 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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