求一批命令

CopperLau 2011-05-20 01:37:15

我现在要根据ip地址胡奇数段和偶数段運行不同的程序,例如 192.168.1.118 是偶數 119 就是奇數

想寫一個bat文件来实现系统自动运行,

求代码,万分感谢。
...全文
101 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Microogle 2011-05-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 just4 的回复:]

BatchFile code
rem 网上都这句,多个连接呢?
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i "ip"') do echo "ip=%%i"
rem 用这句如何
netsh int ip show addr "本地连接" | find /i "IP"
[/Quote]
自动获得的IP用netsh int ip show addr "本地连接" | find /i "IP"可能无法显示。
另外有时候默认的连接名并非"本地连接",而ipconfig至少能够获得一个IP,稍作处理获得多个IP也不是很困难的事。
ipconfig比netsh和wmic确实要方便一些,所以大多数时候都会选择用ipconfig.
就是just4 2011-05-22
  • 打赏
  • 举报
回复
[code=BatchFile]rem 网上都这句,多个连接呢?
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i "ip"') do echo "ip=%%i"
rem 用这句如何
netsh int ip show addr "本地连接" | find /i "IP"
[/code]
Microogle 2011-05-20
  • 打赏
  • 举报
回复
LS变量命名太无语了,objFSO都出来了...
来个bat版的吧:
@echo off
for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i "ip"') do set "ip=%%i"
for /f "delims=. tokens=4" %%j in ("%ip%") do set "flag=%%j"
set /a flag=flag%%2
goto :%flag%
goto :eof

:0
rem 偶数
notepad.exe
goto :eof

:1
rem 奇数
regedit.exe
goto :eof
逍遥无极 2011-05-20
  • 打赏
  • 举报
回复
对了,更多问题请加群:70539804 咨询
逍遥无极 2011-05-20
  • 打赏
  • 举报
回复
您好,请使用这个脚本就可以实现
strComputer = "."
set objFSO = CreateObject("WScript.shell")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
sIP=IPConfig.IPAddress(i)
Next
End If
Next

sLast = Right(sIP,Len(sIP)-InStrRev(sIP,"."))
If sLast Mod 2 =0 Then
' "Ou shu wei"
objFSO.Run("C:\1.exe")
Else
' "Ji Shu Wei"
objFSO.Run("C:\2.exe")
End If

6,849

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧