Board logo

标题: 支付宝20求批处理取本机ip地址最后位做为变量修改文件内容 [打印本页]

作者: kissn    时间: 2019-8-27 22:18     标题: 支付宝20求批处理取本机ip地址最后位做为变量修改文件内容

这个是取本机ip地址最后位做为变量并查找指定目录下ftp.txt内的 /upload,在后面加上/得到的变量数值 使该行结果为cd /upload/变量值/
  1. @echo off
  2. for /f tokens^=1^,2^ delims^=^"^" %%a in ('wmic nicconfig get IPAddress /value ^| findstr /i "IPAddress=[^]"') do (set "ip=%%b")
  3. for /f "tokens=4 delims=." %%a in ("%ip%") do set ip=%%~a
  4. echo,%ip%>E:\ip.txt
  5. set IPFile=E:\IP.txt
  6. set IniFile=E:\ftp.txt
  7. set /p ServerIP=<"%IPFile%"
  8. (for /f "delims=" %%a in ('type "%IniFile%"') do (
  9.     echo %%a|findstr /i "^serverip=" >nul && (
  10.         echo serverip=%ServerIP%
  11.     ) || (
  12.         echo %%a
  13.     )
  14. ))>tmp_Config
  15. move /y tmp_Config "%IniFile%" >nul
  16. pause
复制代码
以下是ftp.txt 内文件内容:
  1. open 192.168.1.169 9999
  2. 2
  3. 2
  4. lcd D:\pt
  5. cd /upload
  6. mput *.txt
  7. prompt on
  8. bye
  9. quit
  10. open 192.168.1.169 8888
  11. 1
  12. 1
  13. prompt off
  14. lcd D:\pt
  15. cd /pt
  16. mget *.txt
  17. close
复制代码

作者: flashercs    时间: 2019-8-27 22:38

本帖最后由 flashercs 于 2019-8-27 22:44 编辑
  1. @echo off
  2. for /f tokens^=1^,2^ delims^=^"^" %%a in ('wmic nicconfig get IPAddress /value ^| findstr /i "IPAddress=[^]"') do (set "ip=%%b")
  3. for /f "tokens=4 delims=." %%a in ("%ip%") do set ip=%%~a
  4. echo,%ip%>E:\ip.txt
  5. set IPFile=E:\IP.txt
  6. set IniFile=E:\ftp.txt
  7. set /p ServerIP=<"%IPFile%"
  8. (for /f "delims=" %%a in ('type "%IniFile%"') do (
  9.     echo %%a|findstr /ric:"^cd /upload" >nul && (
  10.         echo cd /upload/%ServerIP%/
  11.     ) || (
  12.         echo %%a
  13.     )
  14. ))>tmp_Config
  15. move /y tmp_Config "%IniFile%" >nul
  16. pause
复制代码

作者: kissn    时间: 2019-8-27 22:59

回复 2# flashercs


    老哥没毛病。留下支付宝
作者: flashercs    时间: 2019-8-27 23:28

回复 3# kissn


   扫 我头像
作者: kissn    时间: 2019-8-27 23:29

回复 4# flashercs


    已付
作者: Batcher    时间: 2019-8-28 08:04

回复 1# kissn
  1. for /f "tokens=4 delims=." %%a in ("%ip%") do set ip=%%~a
  2. echo,%ip%>E:\ip.txt
  3. set IPFile=E:\IP.txt
  4. set IniFile=E:\ftp.txt
  5. set /p ServerIP=<"%IPFile%"
复制代码
是不是可以简化成:
  1. for /f "tokens=4 delims=." %%a in ("%ip%") do set ServerIP=%%~a
  2. set IniFile=E:\ftp.txt
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2