- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我需要每 10 分钟检查一次我的 IP 地址并将其写入 csv 文件(如果它已更改)。但是,我有几个网卡在使用中。如何在 CMD 中使用其 MAC 地址获取特定卡的 IP 地址?
请参阅下文以修改对 another question 的回复通过 @mousio .虽然它对我不起作用!
@echo off
setlocal enabledelayedexpansion
set "MAC1=Physical Address"
set "MAC2=11-11-11-11-11-11"
set MACfound=false
for /f "usebackq tokens=1-2 delims=:" %%f in (`ipconfig /all`) do (
set "item1=%%f"
set "item2=%%g"
if /i "!item1!"=="!MAC1!" if "!item2!"=="!MAC2!" (
set MACfound=true
) else if not "!item1!"=="!item:IPv4 Address=!" if "!MACfound!"=="true" (
echo Your IP Address is: %%g
set MACfound=false
)
)
请参阅下面的 ipconfig/all 部分响应
Ethernet adapter Ethernet 3:
Connection-specific DNS Suffix . : xyz.xyz.com
Description . . . . . . . . . . . : Intel(R) 82579LM Gigabit Network Connection
Physical Address. . . . . . . . . : 11-11-11-11-11-11
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : 1111::1111:1111:1111:111111(Preferred)
IPv4 Address. . . . . . . . . . . : 111.11.11.11(Preferred)
Subnet Mask . . . . . . . . . . . : 111.111.1.1
Lease Obtained. . . . . . . . . . : Thursday, July 25, 2019 9:51:30 AM
Lease Expires . . . . . . . . . . : Monday, August 26, 2019 12:33:23 PM
Default Gateway . . . . . . . . . : 111.11.1.1
DHCP Server . . . . . . . . . . . : 111.11.11.11
DHCPv6 IAID . . . . . . . . . . . : 111111111
DHCPv6 Client DUID. . . . . . . . : 11-11-11-11-11-11-11-11-11-11-11-11-11-11
DNS Servers . . . . . . . . . . . : 111.11.11.11
111.11.11.11
NetBIOS over Tcpip. . . . . . . . : Enabled
最佳答案
IPconfig
很难解析,因为所需的信息分布在多行中。使用正确的工具。我推荐wmic
:
for /f "tokens=2 delims={}" %%a in ('wmic nicconfig where MACAddress^="11:11:11:11:11:11" get IPAddress /value') do echo %%~a
注意:wmic
中 MAC 地址的格式不同(冒号而不是破折号)。不要忘记转义 =
。
编辑:分隔 IPv4 和 IPv6 地址,只需将字符串与另一个 for
循环分开:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=2 delims={}" %%a in ('wmic nicconfig where MACAddress^="11:11:11:11:11:11" get IPAddress /value') do set "adresses=%%a"
echo All Addresses: %adresses%
for %%a in (%adresses%) do (
echo %%~a|find "." >nul && set "ip4=!ip4!,%%~a
echo %%~a|find ":" >nul && set "ip6=!ip6!,%%~a
)
echo IPv4-Address(es): %ip4:~1%
echo IPv6-Address(es): %ip6:~1%
编辑(由 Mosy 编写):完成所有必需任务的代码,即在 csv 文件中写入 ip 地址,如果它发生变化,则每 10 分钟更新一次:
基本上,同一路径下会有两个批处理文件,第一个名为 ip_main.bat 并包含:
@echo off
echo -- IP ADDRESS UPDATER, PLEASE DO NOT CLOSE! --
set parent=%~dp0%
CD "%parent%"
setlocal enabledelayedexpansion
for /f "tokens=2 delims={}" %%a in ('wmic nicconfig where MACAddress^="11:11:11:11:11:11" get IPAddress /value') do set "adresses=%%a"
for %%a in (%adresses%) do (
echo %%~a|find "." >nul && set "ip4=!ip4!,%%~a
echo %%~a|find ":" >nul && set "ip6=!ip6!,%%~a
)
set ip4_old=%ip4:~1%
set ip6_old=%ip6:~1%
set "ip4=%ip4*=%"
set "ip6=%ip6*=%"
call ip_writer > ip_file.csv
:loop
for /f "tokens=2 delims={}" %%a in ('wmic nicconfig where MACAddress^="11:11:11:11:11:11" get IPAddress /value') do set "adresses=%%a"
for %%a in (%adresses%) do (
echo %%~a|find "." >nul && set "ip4=!ip4!,%%~a
echo %%~a|find ":" >nul && set "ip6=!ip6!,%%~a
)
set ip4_new=%ip4:~1%
set ip6_new=%ip6:~1%
set "ip4=%ip4*=%"
set "ip6=%ip6*=%"
if not "%ip4_new%"=="%ip4_old%" (
call ip_writer > ip_file.csv
set ip4_old=%ip4_new%
)
set "ip4_new=%ip4*=%"
timeout 600 /nobreak > nul
goto loop
第二个批处理文件称为 ip_writer.bat 并包含
@echo off
set parent=%~dp0%
CD "%parent%"
setlocal enabledelayedexpansion
for /f "tokens=2 delims={}" %%a in ('wmic nicconfig where MACAddress^="11:11:11:11:11:11" get IPAddress /value') do set "adresses=%%a"
rem echo All Addresses: %adresses%
for %%a in (%adresses%) do (
echo %%~a|find "." >nul && set "ip4=!ip4!,%%~a
echo %%~a|find ":" >nul && set "ip6=!ip6!,%%~a
)
set ip4=%ip4:~1%
set ip6=%ip6:~1%
echo ip4_address
echo %ip4%
关于windows - 作为 CMD 变量的特定以太网的 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57230764/
我正在寻找的服务器是: 轻量级, 非 buggy , 支持.NET, 在客户端上运行以进行测试, 在Windows上运行 Cassinni太过马车,IIS太昂贵,Apache很难安装,XSP仅是lin
所以我有大约10个短的css文件,可以与mvc应用程序一起使用。 有像 error.css login.css 等等... 仅有一些非常短的CSS文件,这些文件使更新和编辑变得容易(至少对我而言)。我
我正在编写程序来自动化 win32 表单。我正在使用 Microsoft UI 自动化库。我不知道如何获取和调用该表单上的预定义快捷键。现在我只需获取 MenuItem 的 AutomationEle
我有一个在后台线程上运行的及时操作。运行时,我当前将光标置于等待状态: Mouse.OverrideCursor = Cursors.Wait 我刚刚实现了一项功能,允许用户在厌倦等待时单击“取消”按
如何找到所有可能直接或间接调用给定方法的单元测试?当我更改方法时,我希望知道要运行的最佳测试;必须有一个工具! 因为我们有很多接口(interface),所以我对所有调用接口(interface)方法
我想知道,一个类会被装箱吗?我一直假设每个类都有一个虚拟表,可以用来标识类,所以它需要装箱吗? 最佳答案 只有值类型(结构)被装箱。类实例不会被装箱。 关于.net - 类是盒装的吗? 。网,我们在S
所以接下来有一个按钮调用(页面)。它的 href 链接是 site/blah/#。所以我知道它真正运行的 javascript 代码。在我解析完第一页后,我想解析下一页。我如何模拟鼠标点击,以便我可以
我想知道是否有人对解决以下设计问题有好的建议/模式。我有一个命令类的层次结构。在最抽象的层面上,我有一个 ICommand 接口(interface)。执行 ICommand 的 RunCommand
我在资源(xsd 文件)中有几个文件可用于验证收到的 xml 消息。我使用的资源文件名为 AppResources.resx,它包含一个名为 clientModels.xsd 的文件。当我尝试使用这样
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预
(最后的简短版本) 我目前正在开发的软件需要跟踪任意数量的 MS Office 文件,现在需要提供将所有这些文件一起打印的功能,以及一些应用程序数据(可能会发送到打印机作为 .xps、.html 或
我想在不指定命名空间或程序集的情况下按名称(字符串)实例化一个类。像这样(Unity 语法): var processor = container.Resolve("SpecialProcessor"
我有一些代码可以对 64 位整数进行大量比较,但是它必须考虑数字的长度,就好像它被格式化为字符串一样。我无法更改调用代码,只能更改函数。 最简单的方法(除了 .ToString().Length 之外
使用遗留代码,我发现我有很多这样的语句(超过 500 个) bool isAEqualsB = (a == b) ? true : false; 这样重写有意义吗? bool isAEqualsB =
我有这个: AudioPlayer player = new AudioPlayer(); player.Directory = vc.Directory; player.StartTime = vc
我已经阅读了很多关于双重检查锁定的危险的文章,我会努力远离它,但话虽如此,我认为他们的阅读非常有趣。 我正在阅读 Joe Duffy 的这篇关于使用双重检查锁定实现单例的文章: http://www.
对于可变类型,值类型和引用类型之间的行为差异很明显: // Mutable value type PointMutStruct pms1 = new PointMutStruct(1, 2); P
关闭。这个问题需要更多 focused .它目前不接受答案。 想要改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this q
我有一个 Cordova pp 我在 Controller 中调用post方法 它可以在浏览器中工作,但是在构建和调试apk时出现错误 ionic.bundle.js:23826 POST http:
我们正在尝试将时间戳附加到某些 URL 以让内容缓存但在它们发生更改时更新它们。我们有代码可以归结为: DateTime ts = File.GetLastWriteTime(absPath); 其中
我是一名优秀的程序员,十分优秀!