Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / January 2004

Tip: Looking for answers? Try searching our database.

How can I get default gateway address?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nodir Gulyamov - 26 Jan 2004 13:11 GMT
Hello All!
   I need to get default gateway address of local machine or get local
routing table.
Does .Net contain standard API functions? I couldn't find it in
Documentation.

Thank you very much in advance.

Kind regards,
Nodir Gulyamov
Gaurav Khanna [C# MVP] - 28 Jan 2004 07:38 GMT
Hi!

Use the GetAdaptersInfo Win32 API, via PInvoke, and get the Gateway IP
address. The following links should help you:

http://msdn.microsoft.com/library/en-us/iphlp/iphlp/getadaptersinfo.asp
http://support.microsoft.com/?kbid=223025
http://www.codeguru.com/network/ViewAdapterInfo.html

Signature

Regards,
Kumar Gaurav Khanna
-----------------------------------------------------------------
Microsoft MVP - C#/.NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
OpSupport - Spelunking Rotor
http://opsupport.sscli.net/
Bangalore .NET Users' Group
http://groups.msn.com/bdotnet/

>
> Hello All!
[quoted text clipped - 7 lines]
> Kind regards,
> Nodir Gulyamov
Dino Chiesa [Microsoft] - 28 Jan 2004 22:51 GMT
Example:
http://www.winisp.net/cheeso/srcview.aspx?file=MyIpConfig.cs

-Dino

> Hi!
>
[quoted text clipped - 15 lines]
> > Kind regards,
> > Nodir Gulyamov
Willy Denoyette [MVP] - 28 Jan 2004 12:28 GMT
Take a look at the System.Management classes and the WMI class
Win32_NetworkAdapterConfiguration.

Here's sample to get you started.

using System;
using System.Management;
using System.Runtime.InteropServices;
using System.Threading;
public class Wmis {
public static void Main() {
//Index (here 9 as a sample) depends on the number of network adapters and
protocols bound to it.
// Use the Win32_NetworkAdapter class to get the index of the adapter for
which you need to query the configuration.

 using (ManagementObject netw = new
ManagementObject("Win32_NetworkAdapterConfiguration.Index=9"))
 {
  foreach(string gw in netw["DefaultIpGateway"] as string[]) // property is
a string array
      Console.WriteLine( "GateWay\t?{0}?", gw);
 }
}
}

Willy.

> Hello All!
>    I need to get default gateway address of local machine or get local
[quoted text clipped - 6 lines]
> Kind regards,
> Nodir Gulyamov

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.