SDF Sample: Device Network Routing Table

Need to view or update the Netowrk Routing  Table on your CE/ WinMo device?  Smart Device Framework 2.2’s updated NetworkInformation namespace adds a whole lot of new classes, including a full set of classes for routing table access.  Here’s a quick example of displaying the current routes:


IPRoutingTable table = IPRoutingTable.GetRoutingTable();

Debug.WriteLine(“rn*IP Routing Tablern====================”);
Debug.WriteLine(string.Format(“{0}{1}{2}{3}{4}”,
    “[Interface]”.PadRight(16),
    “[Type]”.PadRight(12),
    “[Destination]”.PadLeft(17),
    “[NetMask]”.PadLeft(17),
    “[Next Hop]”.PadLeft(17)));

foreach (IPForwardEntry entry in table)
{
    string intfname = entry.NetworkInterface == null ? intfname = “{Loopback}” : entry.NetworkInterface.Name;
    Debug.WriteLine(string.Format(“{0}{1}{2}{3}{4}”,
    intfname.PadRight(16),
    entry.RouteType.ToString().PadRight(12),
    entry.Destination.ToString().PadLeft(17),
    entry.SubnetMask.ToString().PadLeft(17),
    entry.NextHop.ToString().PadLeft(17)));
}


Can’t be much simpler than that.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s