|
-
Feb 16th, 2010, 04:01 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Get mac address of gateway
I'm trying to figure out how to view the default gatways ip address and then get the mac address from that
Any ideas on how to see what the computers defualt gateway is?
-
Feb 16th, 2010, 04:33 PM
#2
Re: Get mac address of gateway
The gateway is defined on a per network card level, so this code will get you the Gateway for each of the NICs installed on a machine:
Code:
Dim sb As New StringBuilder
sb.AppendLine()
For Each n As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
sb.AppendLine(n.Description)
sb.AppendLine("MAC:" & n.GetPhysicalAddress().ToString())
For Each u As UnicastIPAddressInformation In n.GetIPProperties().UnicastAddresses
sb.AppendLine("IP:" & u.Address.ToString())
Next
For Each g As GatewayIPAddressInformation In n.GetIPProperties().GatewayAddresses
sb.AppendLine("Gateway:" & g.Address.ToString())
Next
Next
MessageBox.Show(sb.ToString())
-
Feb 16th, 2010, 04:38 PM
#3
Fanatic Member
Re: Get mac address of gateway
Well the default gateway varies for every user.
For example, my default gateway is 192.168.1.1 (that's the router default gateway).
Take a look at this example to get the default gateway:
http://www.java2s.com/Tutorial/CShar...figuration.htm
It's in C# but mentioned and VB.Net are very similar so there shouldn't be any problems porting the code.
You might also want to take a look at this VB.Net example, just to get some ideas (since this code requires user defined information)
http://www.xtremevbtalk.com/archive/.../t-251709.html
Also this VB6 example:
http://bytes.com/topic/visual-basic-...efault-gateway
Happy coding 
*EDIT* Negative0: damn, you won this time... it took too long time for me to paste the links xD
-
Feb 16th, 2010, 08:50 PM
#4
Re: Get mac address of gateway
 Originally Posted by Negative0
The gateway is defined on a per network card level, so this code will get you the Gateway for each of the NICs installed on a machine:
Code:
Dim sb As New StringBuilder
sb.AppendLine()
For Each n As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
sb.AppendLine(n.Description)
sb.AppendLine("MAC:" & n.GetPhysicalAddress().ToString())
For Each u As UnicastIPAddressInformation In n.GetIPProperties().UnicastAddresses
sb.AppendLine("IP:" & u.Address.ToString())
Next
For Each g As GatewayIPAddressInformation In n.GetIPProperties().GatewayAddresses
sb.AppendLine("Gateway:" & g.Address.ToString())
Next
Next
MessageBox.Show(sb.ToString())
That code looks familiar.
-
Feb 16th, 2010, 09:51 PM
#5
Re: Get mac address of gateway
 Originally Posted by dbasnett
That code looks familiar.
Really? I wrote it from scratch. I googled to find out the classes to use, but the code is mine.
-
Feb 17th, 2010, 06:14 AM
#6
Re: Get mac address of gateway
 Originally Posted by Negative0
Really? I wrote it from scratch. I googled to find out the classes to use, but the code is mine.
I didn't mean anything, sorry.
-
Feb 17th, 2010, 11:00 PM
#7
Thread Starter
Fanatic Member
Re: Get mac address of gateway
 Originally Posted by Zeelia
I am working in c# so i was going to converet it anyway. There are alot more people in the vb rooms so its usually faster with more information if i just post here and then convert it over
StringBuilder sb = new StringBuilder();
sb.AppendLine();
foreach (NetworkInterface n in NetworkInterface.GetAllNetworkInterfaces())
{
sb.AppendLine(n.Description);
sb.AppendLine("MAC:" + n.GetPhysicalAddress().ToString());
foreach (UnicastIPAddressInformation u in n.GetIPProperties().UnicastAddresses)
{
sb.AppendLine("IP:" + u.Address.ToString());
}
foreach (GatewayIPAddressInformation g in n.GetIPProperties().GatewayAddresses)
{
sb.AppendLine("Gateway:" + g.Address.ToString());
}
}
MessageBox.Show(sb.ToString());
-
Feb 17th, 2010, 11:00 PM
#8
Thread Starter
Fanatic Member
Re: Get mac address of gateway
 Originally Posted by Negative0
The gateway is defined on a per network card level, so this code will get you the Gateway for each of the NICs installed on a machine:
Code:
Dim sb As New StringBuilder
sb.AppendLine()
For Each n As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
sb.AppendLine(n.Description)
sb.AppendLine("MAC:" & n.GetPhysicalAddress().ToString())
For Each u As UnicastIPAddressInformation In n.GetIPProperties().UnicastAddresses
sb.AppendLine("IP:" & u.Address.ToString())
Next
For Each g As GatewayIPAddressInformation In n.GetIPProperties().GatewayAddresses
sb.AppendLine("Gateway:" & g.Address.ToString())
Next
Next
MessageBox.Show(sb.ToString())
thanks this worked perfectly
(see above comment i converted it to c#)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|