Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

networking - Get wired MAC address from computer/server

I am thinking about using the wired MAC-adr as a unique value in a program. So i need to be sure the MAC-adr is the wired one and NOT the wireless.

$mac = gwmi -computer $compname win32_NetworkAdapterConfiguration | select MACAddress

This is what I started with, but it gives me two addresses. First one is the one I want: 00:00:11:11:22:22 The last one is the wireless address: 00:1F:3C:8E:61:D8

I can't just sort like: select -first 1. Because I don't know what this will get me on other computers.. And btw, this DOES work on ipV6 as well as ipV4?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this way:

$mac = gwmi -computer $compname win32_NetworkAdapter | ? { $_.AdapterType -match "802.3" } |  select MACAddress

If there's more than one you need to do a selection.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...