找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
楼主: wlishihua

[系统相关] [已解决]批处理如何根据IP地址判断是否执行程序?

[复制链接]
 楼主| 发表于 2021-8-14 20:15:10 | 显示全部楼层
回复 15# idwma


   运行时就一个黑框,不走了
发表于 2021-8-14 20:22:55 | 显示全部楼层
回复 16# wlishihua


    那这样看行不行
  1. @echo off
  2. call :n 111.exe ddd.exe aaa.exe ............
  3. pause
  4. goto :eof

  5. :n
  6. set/a n+=1
  7. ipconfig|findstr /i "ipv4.*192\.168\.1\.%n%"&&start %1&&goto :eof
  8. shift
  9. if not "%n%"=="" goto :n
复制代码

评分

参与人数 1技术 +1 收起 理由
wlishihua + 1 没有什么不可能的,谢谢你

查看全部评分

 楼主| 发表于 2021-8-14 20:38:40 | 显示全部楼层
回复 17# idwma


    OK,但是只能启动exe,不能启动快捷方式
 楼主| 发表于 2021-8-14 20:42:16 | 显示全部楼层
回复 18# wlishihua
写法不太好理解,就是说111.exe对应的是192.168.1.1  DDD.EXE 对应的就是192.168.1.2  依次类推,是吗?
查询从192.168.1.1开始,到192.168.1.255结束
 楼主| 发表于 2021-8-14 20:46:53 | 显示全部楼层
本帖最后由 wlishihua 于 2021-8-14 20:50 编辑

回复 17# idwma


@echo off
cd /d %~dp0
for /f "delims=: tokens=1,2" %%a in ('ipconfig ^|find "IPv4"') do echo,%%b&set ips=%%b
if %ips% == 192.168.1.1start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.2  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
if %ips% == 192.168.1.3  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"

exit
这个好理解,能启动lnk文件

比如说从192.168.2到192.168.100,只执行一个文件  192.168.101到192.168.253  又执行另外一个文件,你那个代码怎么办?
 楼主| 发表于 2021-8-14 20:54:12 | 显示全部楼层
本帖最后由 wlishihua 于 2021-8-14 20:59 编辑

回复 17# idwma

@echo off
cd /d %~dp0
for /f "delims=: tokens=1,2" %%a in ('ipconfig ^|find "IPv4"') do echo,%%b&set ips=%%b
if %ips% == 192.168.1.1  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.2  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.3  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.4  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"

if %ips% == 192.168.1.5  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
if %ips% == 192.168.1.6  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
if %ips% == 192.168.1.7  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
if %ips% == 192.168.1.8  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
.........
exit
::四个IP地址为一组

你那个代码怎么写
if %ips% == 192.168.1.1  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.2  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.3  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.4  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
如果是253个IP,那么这个就要写253个IP地址,能不能简化一下
 楼主| 发表于 2021-8-14 21:00:41 | 显示全部楼层
回复 5# yakeyun


    @echo off
cd /d %~dp0
for /f "delims=: tokens=1,2" %%a in ('ipconfig ^|find "IPv4"') do echo,%%b&set ips=%%b
if %ips% == 192.168.1.1  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.2  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.3  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.4  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"

if %ips% == 192.168.1.5  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
if %ips% == 192.168.1.6  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
if %ips% == 192.168.1.7  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
if %ips% == 192.168.1.8  start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
.........
exit
::四个IP地址为一组

代码怎么写
if %ips% == 192.168.1.1  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.2  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.3  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
if %ips% == 192.168.1.4  start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
如果是253个IP,那么这个就要写253个IP地址,能不能简化一下 用分组的方式
发表于 2021-8-14 21:19:02 | 显示全部楼层
回复 21# wlishihua

改一下可以快捷方式
    好像也可以四个一跳,后面的多少一跳以此类推来改
这里的1到4,4到8,8到253
  1. @echo off
  2. call :n "C:\Users\Administrator\Desktop\Microsoft Edge.lnk" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
  3. pause
  4. goto :eof

  5. :n
  6. set/a n+=1
  7. ipconfig|findstr /i "ipv4.*192\.168\.1\.%n%"&&start "" "%~1"&&goto :eof
  8. if %n%==4 shift
  9. if %n%==8 shift
  10. if %n%==253 shift
  11. if not "%n%"=="" goto :n
复制代码

评分

参与人数 1技术 +1 收起 理由
wlishihua + 1 非常好

查看全部评分

 楼主| 发表于 2021-8-14 21:36:14 | 显示全部楼层
回复 23# idwma


    OK  谢谢!
 楼主| 发表于 2021-8-14 21:39:50 | 显示全部楼层
本帖最后由 wlishihua 于 2021-8-14 21:58 编辑

回复 23# idwma
还是这样我们以MAC地址来确定,


@ipconfig /all|FIND /I "4C-CC-6A-FC-D6-59">NUL 2>NUL&& start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"
@ipconfig /all|FIND /I "4C-CC-68-FC-D6-58">NUL 2>NUL&& start "" "C:\Users\Administrator\Desktop\MHTCGI\mhtcgi.exe"

@ipconfig /all|FIND /I "4C-CC-69-FC-D6-60">NUL 2>NUL&& start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"
@ipconfig /all|FIND /I "4C-CC-6A-FC-D6-61">NUL 2>NUL&& start "" "C:\Users\Administrator\Desktop\Microsoft Edge.lnk"

@ipconfig /all|FIND /I "4C-CC-65-FC-D6-66">NUL 2>NUL&& start "" "C:\Users\Administrator\Desktop\ddd.exe"
@ipconfig /all|FIND /I "4C-CC-6A-FC-D6-88">NUL 2>NUL&& start "" "C:\Users\Administrator\Desktop\ddd.exe"
这个怎么分组?
分不了组我就要写253个
发表于 2021-8-14 22:17:05 | 显示全部楼层
回复 25# wlishihua

这个地址不连序
    如果先把这两百多个mac按顺序排列好,也可以操作一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-20 22:21 , Processed in 0.030296 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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