-
July 16th, 2006, 01:25 PM
#1
Senior Member
LAN/WLAN Switch
Hello,
I have a pc with LAN i WLAN network cards. I want to make a c++/perl/pascal program that enable/disable the WLAN card when the LAN cable is disconnected/connected. Can anybody help me with some solution, api, source or something ... The OS is Windows XP.
10x
-
July 16th, 2006, 09:20 PM
#2
Hi
I am lacking a bit time, so I will not provide a
out-of-the-box solution, sorry.
How to enable/disable a network interface?
In this article[1], several ways are presented to
enable/disable a network interface programmatically.
I would use shell network interfaces.
Note that the Iphelper-API administrative enabling/
disabling is not equivalent to enable/disable the
interface in the network neighborhood. Furthermore,
with Iphelper you cannot access a disabled interface.
How to check the status of a network interface?
The Iphelper-API is exactly what you need. The
snippet is taken from microsoft.com[2] with a
few modifications of myself at the end.
Code:
// Declare and initialize variables.
PMIB_IFTABLE ifTable;
PMIB_IFROW pMibIfRow;
DWORD dwSize = 0;
DWORD dwRetVal = 0;
int enumEntry;
// Allocate memory for our pointers.
ifTable = (MIB_IFTABLE*) malloc(sizeof(MIB_IFTABLE));
pMibIfRow = (MIB_IFROW*) malloc(sizeof(MIB_IFROW));
// Before calling GetIfEntry, we call GetIfTable to make
// sure there are entries to get.
// Make an initial call to GetIfTable to get the
// necessary size into dwSize
if (GetIfTable(ifTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
GlobalFree(ifTable);
ifTable = (MIB_IFTABLE *) malloc (dwSize);
}
// Make a second call to GetIfTable to get the actual
// data we want.
if ((dwRetVal = GetIfTable(ifTable, &dwSize, 0)) == NO_ERROR) {
for (enumEntry=0;enumEntry<ifTable->dwNumEntries;enumEntry++){
printf("Interface Index: %d\n",ifTable->table[enumEntry].dwIndex);
pMibIfRow->dwIndex = ifTable->table[enumEntry].dwIndex;
if ((dwRetVal = GetIfEntry(pMibIfRow)) == NO_ERROR) {
printf("\tDescription: %s\n", pMibIfRow->bDescr);
printf("\tStatus: %d\n", pMibIfRow->dwOperStatus);
}
else {
printf("GetIfEntry failed.\n");
// Here you can use FormatMessage to find out why
// it failed.
}
}
}
The operation status dwOperStatus is also enumerated on microsoft[3].
E.g. Status "5" is connected.
Combine the two, then you have your little program.
Cheers
[1] http://www.gershnik.com/faq/manage.asp#enable
[2] http://msdn.microsoft.com/library/de...getifentry.asp
[3] http://msdn.microsoft.com/library/de.../mib_ifrow.asp
If the only tool you have is a hammer, you tend to see every problem as a nail.
(Abraham Maslow, Psychologist, 1908-70)
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
|
|