Obtaining a default gateway IP address from a Win2K workstation
using Visual Basic 5.0
--------------------------------------------------------------------------------
Visual Basic 5.0
How do you Obtain a default gateway IP address from a Win2K workstation ?
1) I tried with OCX Winsock but it only have LocalIP property method not the method to obtain a default gateway.
2) The API GetIpForwardTable will allowed you to access a default gateway IP address, but I have not found the code example for it. Below is a C code. Maybe somebody could translate that to VB
============================
Local_IP = Winsock1.LocalIP
============================
Code:
#include <iphlpapi.h>
...
BOOL YourClass::CheckConnection()
{
MIB_IPFORWARDTABLE* pft;
DWORD dwTableSize = 0;
BOOL bHasDefaultRoute = FALSE;
GetIpForwardTable(NULL, &dwTableSize, FALSE);
pft = (MIB_IPFORWARDTABLE*) new BYTE[dwTableSize];
if (GetIpForwardTable(pft,
&dwTableSize,
TRUE) == NO_ERROR)
{
for (unsigned int nIndex = 0;
nIndex < pft->dwNumEntries;
nIndex++)
{
if (pft->table[nIndex].dwForwardDest == 0)
// Default route to gateway
{
bHasDefaultRoute = TRUE;
break;
}
}
}
delete pft;
return bHasDefaultRoute;
}
http://www.codeguru.com/mfc/comments/56235.shtml