楼 主
多网卡下如何实现读出板载网卡MAC
发表于 2008-05-22 11:23 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
多网卡(一个板载网卡,多个外接网卡)下如何实现读出板载网卡MAC(并且每个网卡有设IP号,网卡蕊片不一样!板载网卡上网!其他网卡不接网线)(WINDOWS98/2000/XP下测试用)
我写了段代码,但同时读出来三个.你看一下能不能实理那个效果!
@echo off
setlocal Enabledelayedexpansion
ipconfig /all >ipconfig.txt
find "Physical Address" ipconfig.txt >phyaddr.txt
for /f "skip=1 tokens=12" %%a in (phyaddr.txt) do (
set var=%%a
if not exist \\192.168.94.27\t\testdate\winpass.log goto fail
find /i /c "!var!" \\192.168.94.27\t\testdate\winpass.log
if not errorlevel 1 goto mac
echo !var!>>\\192.168.94.27\t\testdate\winpass.log
)
endlocal
end
:mac
cls
echo. The mas is used!
echo. The mas is used!
echo. The mas is used!
echo. The mas is used!
echo. The mas is used!
pause
第 2 楼
请测试后反馈:
发表于 2008-05-22 11:35 · 中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
积分 3,105 发帖 1,276 注册 2008-03-08 13:00 18年会员 UID 112398 性别 男
状态 离线
如主板网卡默认是第一网卡:
@echo off
for /f "tokens=2 delims=:" %%i in ('ipconfig /all^|findstr /c:"Physical Address"') do set mac=%%i&goto echo
:echo
set mac=%mac:~1%
echo %mac%
pause>nul
[
Last edited by zw19750516 on 2008-5-22 at 12:36 PM ]
批处理之家新域名:www.bathome.net
第 3 楼
谢谢
发表于 2008-05-22 11:39 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
谢谢!!我们这里是做测试的,其实我的最终功能是要判断服务器上的日志文件里面有没有被测试板的板载MAC数据来判断出它是不是被测试过的主板.呵呵!有劳了,谢谢!
第 4 楼
发表于 2008-05-22 12:55 · 中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
积分 3,105 发帖 1,276 注册 2008-03-08 13:00 18年会员 UID 112398 性别 男
状态 离线
如板载网卡不是默认第一网卡就麻烦点:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('ipconfig /all') do (
set /a n+=1
set _!n!=%%i
echo %%i|findstr /c:"IP Address">nul&&set m=!n!
)
set /a m-=2
set str=!_%m%!
set mac=%str:~-18%
echo %mac%
pause>nul
----------------------------------------------------------------------------------------------------------
&&我还是解释下这段代码吧:
首先是将ipconfig /all所有的行都赋于数值变量,即用for读取一行就将n值加
1(初始n值为0),然后把这一行所有的字符赋值给_!n!;
然后再在所有的数值变量也就是ipconfig /all所有行中逐行查找IP Address字
符串,如找到则将这个行号赋值给m;
在ipconfig /all中可以看到有mac地址的行处于有IP Address字符行上面二行,
所以把m值减2;
最后截取_%m%(m已减2)后面的18个字符即为板载网卡mac。
----------------------------------------------------------------------------------------------------------
还是用if代替findstr来提高效率:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('ipconfig /all') do (
set str=%%i&set /a n+=1
set _!n!=%%i
if "!str:~8,10!"=="IP Address" set m=!n!
)
set /a m-=2
set str=!_%m%!
set mac=%str:~-18%
echo %mac%
pause>nul
[
Last edited by zw19750516 on 2008-5-22 at 11:20 PM ]
批处理之家新域名:www.bathome.net
第 5 楼
我调不出效果呀!
发表于 2008-05-22 13:42 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
我调不出效果呀! "||"这个判断在WIN2000下好像用不了!请回复!谢谢!
第 6 楼
发表于 2008-05-22 14:02 · 中国 上海 联通
版主
★★★★★
积分 9,023 发帖 5,017 注册 2007-05-31 19:39 19年会员 UID 89899 性别 男
状态 离线
把4楼的代码中echo off删除,再运行一边,把运行结果贴出来看看。
第 7 楼
这是显示结果!
发表于 2008-05-22 14:11 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
E:\>set /a m-=2
E:\>set str=!_36!
E:\>set mac=. . . . . . : Yes
E:\>echo . . . . . . : Yes 1>>mac.log
E:\>pause1>nul
第 8 楼
发表于 2008-05-22 15:11 · 中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
积分 3,105 发帖 1,276 注册 2008-03-08 13:00 18年会员 UID 112398 性别 男
状态 离线
晕,请贴出你的ipconfig /all,我这里没有WIN2000
[ Last edited by zw19750516 on 2008-5-22 at 03:13 PM ]
批处理之家新域名:www.bathome.net
第 9 楼
这个是我的机子上的,测试和这差不多,就是一个网卡有IP!
发表于 2008-05-22 15:16 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
Windows IP Configuration
Host Name . . . . . . . . . . . . : gc0427
Primary Dns Suffix . . . . . . . : evoc.local
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : evoc.local
Ethernet adapter VMware Network Adapter VMnet8:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
Physical Address. . . . . . . . . : 00-50-56-C0-00-08
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.230.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter VMware Network Adapter VMnet1:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet1
Physical Address. . . . . . . . . : 00-50-56-C0-00-01
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.229.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter 本地连接 7:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Marvell Yukon 88E8040 PCI-E Fast Ethernet Controller
Physical Address. . . . . . . . . : 00-E0-B0-F2-2F-0C
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.94.50
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.94.1
DHCP Server . . . . . . . . . . . : 172.16.0.198
DNS Servers . . . . . . . . . . . : 172.16.0.198
202.96.174.66
Primary WINS Server . . . . . . . : 172.16.0.198
Lease Obtained. . . . . . . . . . : 2008年5月20日 16:29:43
Lease Expires . . . . . . . . . . : 2008年5月28日 16:29:43
第 10 楼
如下是本机板载网卡MAC
发表于 2008-05-22 15:18 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Marvell Yukon 88E8040 PCI-E Fast Ethernet Controller
Physical Address. . . . . . . . . : 00-E0-B0-F2-2F-0C
第 11 楼
zw19750516注意一下,
发表于 2008-05-22 15:27 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
我刚刚到测试机器上看了一下,那里除了板载有IP外,其它的都不会显IP.
第 12 楼
发表于 2008-05-22 15:28 · 中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
积分 3,105 发帖 1,276 注册 2008-03-08 13:00 18年会员 UID 112398 性别 男
状态 离线
172.16.0.198这个值是固定的不
把测试的ipconfig /all 发出来,我这里的确实和你那里的有很大的不同。
[ Last edited by zw19750516 on 2008-5-22 at 03:30 PM ]
批处理之家新域名:www.bathome.net
第 13 楼
如下
发表于 2008-05-22 15:29 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
大至是这样:
Windows IP Configuration
Host Name . . . . . . . . . . . . : gc0427
Primary Dns Suffix . . . . . . . : evoc.local
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : evoc.local
Ethernet adapter VMware Network Adapter VMnet8:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
Physical Address. . . . . . . . . : 00-50-56-C0-00-08
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . :
Subnet Mask . . . . . . . . . . . :
Default Gateway . . . . . . . . . :
Ethernet adapter VMware Network Adapter VMnet1:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet1
Physical Address. . . . . . . . . : 00-50-56-C0-00-01
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . :
Subnet Mask . . . . . . . . . . . :
Default Gateway . . . . . . . . . :
Ethernet adapter 本地连接 7:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Marvell Yukon 88E8040 PCI-E Fast Ethernet Controller
Physical Address. . . . . . . . . : 00-E0-B0-F2-2F-0C
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.94.50
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.94.1
DHCP Server . . . . . . . . . . . : 172.16.0.198
DNS Servers . . . . . . . . . . . : 172.16.0.198
202.96.174.66
Primary WINS Server . . . . . . . : 172.16.0.198
Lease Obtained. . . . . . . . . . : 2008年5月20日 16:29:43
Lease Expires . . . . . . . . . . : 2008年5月28日 16:29:43
第 14 楼
发表于 2008-05-22 15:32 · 中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
积分 3,105 发帖 1,276 注册 2008-03-08 13:00 18年会员 UID 112398 性别 男
状态 离线
很好解决,把我4楼的set /a m-=2改为set /a m-=3
批处理之家新域名:www.bathome.net
第 15 楼
测试机器那里没有DHCP和DNS
发表于 2008-05-22 15:41 · 中国 广东 深圳 诺瓦科技发展有限公司
初级用户
★
积分 76 发帖 32 注册 2008-05-14 15:14 18年会员 UID 118657 性别 男
状态 离线
测试机器那里没有DHCP和DNS. SORRY!我是在我的办公电脑上导出的! 大至如下
Ethernet adapter 本地连接 7:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Marvell Yukon 88E8040 PCI-E Fast Ethernet Controller
Physical Address. . . . . . . . . : 00-E0-B0-F2-2F-0C
IP Address. . . . . . . . . . . . : 192.168.94.50
Subnet Mask . . . . . . . . . . . : 255.255.255.0
论坛跳转:
— 请选择 —
站务公告 & 版主讨论
意见反馈 & 网友交流
DOS学习入门 & 精彩文章 (教学室)
DOS疑难解答 & 问题讨论 (解答室)
DOS启动盘 & LOGO技术 (启动盘室)
DOS批处理 & 脚本技术(批处理室)
DOS媒体世界 & 网络技术 (多媒体室)
DOS汉化世界 & 中文系统 (中文化室)
DOS开发编程 & 发展交流 (开发室)
DOS软件下载 & 游戏分享 (下载室)
GRUB4DOS、SYSLINUX及其它启动管理软件讨论专区
其它操作系统综合讨论区
WinPE、PowerShell及其它命令行系统专区
贴图灌水、文学娱乐专区
网络日志(Blog)
论坛回收站
├ 链接失效,待修正