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

[其他] 如何实现间歇性地更换IP地址

[复制链接]
发表于 2010-6-24 22:47:03 | 显示全部楼层

回复 15楼 的帖子

这个我不会, 但有一种隐藏运行的技术
  1. @echo off & setlocal enabledelayedexpansion
  2. if /i "%1" equ "hide" goto begin
  3. if /i "%1" equ "show" goto begin

  4. set /p show=需要显示窗口界面吗^(y/n^)[直接回车=不显示]:)
  5. if /i "%show:~0,1%" equ "y" goto begin
  6. (call :showWindow hide)

  7. :begin

  8. call :foundACName ACName
  9. set "ipa=192.168.1.101" & set "ipb=192.168.1.102" & set "mask=255.255.255.0" & set "gateway=192.168.1.1"
  10. set /a ms=2 & rem ms 为时间间隔
  11. for /l %%k in (0 0 0) do (
  12.   set /a "diff=1!time:~3,2!-100+60-mm, diff%%=60"
  13.   if !diff! geq !ms! ( set /a mm=1!time:~3,2!-100
  14.     for /f "tokens=2 delims=[]" %%i in ('ping -n 1 %computername% ^| find "["') do (
  15.       if "%%i"=="!ipa!" (netsh interface ip set address name="!ACName!" source=static addr=!ipb! mask=!mask! gateway=!gateway! 1
  16.       ) else (
  17.         netsh interface ip set address name="!ACName!" source=static addr=!ipa! mask=!mask! gateway=!gateway! 1
  18.       )
  19.       for /f "tokens=2 delims=[]" %%a in ('ping -n 1 %computername% ^| find "["') do echo %%a
  20.     )
  21.   )
  22. )
  23. exit /b

  24. :foundACName ACName rem 找出当前活动连接的名称
  25. for /f "tokens=2 delims=[]" %%i in ('ping -n 1 %computername% ^| find "["') do (
  26.   for /f "skip=1" %%a in ('wmic nicconfig where "ipenabled='true'" get index') do (
  27.     for /f "delims=}{" %%b in ('wmic nicconfig where "index=%%a" get ipaddress') do (
  28.       if "%%~b"=="%%i" for /f "tokens=1-2 delims==" %%c in ('wmic nic where "index=%%a" get NetConnectionID /value') do (
  29.         for /f "delims=" %%z in ("%%d") do set "_%%c=%%z"
  30.       )
  31.     )
  32.   )
  33. )
  34. set %1=!_NetConnectionID!&echo 当前活动连接为: "!%1!"
  35. exit /b

  36. :showWindow
  37. if /i "%1" equ "hide" (set intWindowStyle=0) else (set intWindowStyle=5)
  38. mshta vbscript:createobject("wscript.shell").run("%~snx0 %1",!intWindowStyle!)(window.close)&&exit
  39. exit /b
复制代码
要想关闭隐藏的 cmd , 可以用一种野蛮的方式关闭所有的 cmd
  1. taskkill /f /t /im cmd.exe
复制代码

[ 本帖最后由 neorobin 于 2010-6-24 23:07 编辑 ]
 楼主| 发表于 2010-6-25 06:41:15 | 显示全部楼层
实在太感谢楼上的师傅了在请教一下如何不询问直接隐藏cmd?谢谢
这样我直接随系统启动就ok了对用户绝对透明了
 楼主| 发表于 2010-6-25 06:44:57 | 显示全部楼层
找出当前活动连接的名称
这段也不要我直接直接写上去就ok谢谢
 楼主| 发表于 2010-6-25 07:51:06 | 显示全部楼层
师傅写的cpu占用100%啊我胡写的那个占用就不高不知道为什么,能不能把占用降下来
发表于 2010-6-25 16:50:39 | 显示全部楼层
  1. @echo off & setlocal enabledelayedexpansion
  2. if /i "%1" equ "hide" goto begin
  3. if /i "%1" equ "show" goto begin
  4. rem 直接隐藏运行的方法: 删除或注解下面的一行
  5. set /p show=需要显示窗口界面吗^(y/n^)[直接回车=不显示]:
  6. if /i "%show:~0,1%" equ "y" goto begin
  7. (call :showWindow hide)

  8. :begin
  9. set "ACName=本地连接"
  10. (call :findACName ACName) & rem 不用搜索活动连接的话, 删除或注解本行.
  11. set /a ipts=2,ipte=9,ipt=3& rem ipts--ipte 指定可用的 ip 地址范围, 例如: 192.168.0.2--192.168.0.9, ipt 取范围中的任一值.
  12. set "iph=192.168.0." & set "mask=255.255.255.0" & set "gateway=!iph!1" & set ms=120 & rem ms: 时间间隔秒数
  13. netsh interface ip set address "!ACName!" static !iph!!ipt! !mask! !gateway! 1
  14. for /l %%k in (0 0 0) do (
  15.   set /a "ipt=(ipt+1-ipts)%%(ipte-ipts+1)+ipts"
  16.   netsh interface ip set address "!ACName!" static !iph!!ipt! !mask!
  17.   for /f "tokens=2 delims=[]" %%a in ('ping -n 1 %computername% ^| find "["') do echo %%a
  18.   ping -n !ms! 127.1>nul
  19. )
  20. exit /b

  21. :findACName ACName rem 找出当前活动连接的名称
  22. for /f "tokens=2 delims=[]" %%i in ('ping -n 1 %computername% ^| find "["') do (
  23.   for /f "skip=1" %%a in ('wmic nicconfig where "ipenabled='true'" get index') do (
  24.     for /f "delims=}{" %%b in ('wmic nicconfig where "index=%%a" get ipaddress') do (
  25.       if "%%~b"=="%%i" for /f "tokens=1-2 delims==" %%c in ('wmic nic where "index=%%a" get NetConnectionID /value') do (
  26.         for /f "delims=" %%z in ("%%d") do set "_%%c=%%z"
  27.       )
  28.     )
  29.   )
  30. )
  31. set %1=!_NetConnectionID!&echo 当前活动连接为: "!%1!"
  32. exit /b

  33. :showWindow
  34. if /i "%1" equ "hide" (set intWindowStyle=0) else (set intWindowStyle=5)
  35. mshta vbscript:createobject("wscript.shell").run("%~snx0 %1",!intWindowStyle!)(window.close)&&exit
  36. exit /b
复制代码

评分

参与人数 1PB +10 收起 理由
batman + 10 好热心,论坛就需要兄弟这样的热心人,好!

查看全部评分

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

本版积分规则

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

GMT+8, 2026-3-19 02:34 , Processed in 0.019555 second(s), 7 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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