Get the MAC Address

G

Guest

Hi EveryBody:

Can Some body tell me if my knowldge right that there are three types of MAC
address:

1\ the first one is for the lan network adapter

2\ and the second one for the wireless network adpter

3\ and the last one for the modem.

If that is correct can Some body tell me how can I get them programaticaaly
with vb.net code or redirect me to any site that might help me ?

any help will be appreciated

regard's

Husam
 
P

Patrick Steele

Hi EveryBody:

Can Some body tell me if my knowldge right that there are three types of MAC
address:

1\ the first one is for the lan network adapter

2\ and the second one for the wireless network adpter

3\ and the last one for the modem.

If that is correct can Some body tell me how can I get them programaticaaly
with vb.net code or redirect me to any site that might help me ?

Use WMI:

http://tinyurl.com/2umjqj
 
I

Ivica Muruzovic

Hi EveryBody:

Can Some body tell me if my knowldge right that there are three types of MAC
address:

1\ the first one is for the lan network adapter

2\ and the second one for the wireless network adpter

3\ and the last one for the modem.

If that is correct can Some body tell me how can I get them programaticaaly
with vb.net code or redirect me to any site that might help me ?

any help will be appreciated

regard's

Husam

Imports System.Net.NetworkInformation

Dim networkcard() As NetworkInterface =
NetworkInterface.GetAllNetworkInterfaces()
Public netCard As String =
networkcard(0).GetPhysicalAddress.ToString

or use for ... next to inerate throw all network cards
 
N

Newbie Coder

Husam,

There are a million & one pieces of code plastered over the Internet regarding
this using WMI...

Add a Listbox (lstAdapters)
Add reference to System.Management
Use an Import to System.Management

Use the primitive code below:

Private Sub FillNetworkAdapters()
Dim mc As ManagementClass = New
ManagementClass("Win32_NetworkAdapterConfiguration")
Dim mo As ManagementObject
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim strAdapter As String
Dim strInfo As String
For Each mo In moc
If CBool(mo.Item("IPEnabled")) Then
strAdapter = mo.Item("Caption").ToString().Substring(11)
lstAdapters.Items.Add(String.Format("{0} MAC: {1}",
strAdapter, GetMACAddress(strAdapter)))
End If
Next
End Sub

Private Function GetMACAddress(ByVal Adapter As String) As String
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
If CBool(mo.Item("IPEnabled")) Then
Dim strAdapter As String
strAdapter = mo.Item("Caption").ToString().Substring(11)
If strAdapter = Adapter Then
Return mo.Item("MacAddress").ToString()
End If
End If
Next
End Function

The 'FillNetworkAdapters' get's the name of the adapter & the 'GetMACAddress'
returns the MAC address for that adapter

Sorry but the code can be tidied up considerably as its just part of a project I
wrote back in 2004

=====

Also, never click on these TINY URL's that people paste as they could be hiding
anything. Some spammers & many scammers or webcam prostitutes also use them. Not
saying Patrick is any of these but he could paste in the full url instead, but
wants to know how many fools actually clicked on his links
 
A

AcidCool19

It works but how do we do to retrieve the MAC address of each network interface installed on a single host
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top