Home > Back-end >  Local connection card state judgment
Local connection card state judgment

Time:09-25

Windows 7 64 - bit systems, using D7 how to judge the state of the local connection network card, if disabled, or open?

CodePudding user response:

No test, find online,

The unit AdpUtils;
Interface
USES Windows;
Const
MAX_INTERFACE_NAME_LEN=256;
MAXLEN_PHYSADDR=8;
MAXLEN_IFDESCR=256;
MIB_IF_TYPE_OTHER=1;
MIB_IF_TYPE_ETHERNET=6;
MIB_IF_TYPE_TOKENRING=9;
MIB_IF_TYPE_FDDI=15;
MIB_IF_TYPE_PPP=23;
MIB_IF_TYPE_LOOPBACK=24;
MIB_IF_TYPE_SLIP=28;
MIB_IF_ADMIN_STATUS_UP=1;
MIB_IF_ADMIN_STATUS_DOWN=2;
MIB_IF_ADMIN_STATUS_TESTING=3;
MIB_IF_OPER_STATUS_NON_OPERATIONAL=0;
MIB_IF_OPER_STATUS_UNREACHABLE=1;
MIB_IF_OPER_STATUS_DISCONNECTED=2;
MIB_IF_OPER_STATUS_CONNECTING=3;
MIB_IF_OPER_STATUS_CONNECTED=4;
MIB_IF_OPER_STATUS_OPERATIONAL=5;
Type
MIB_PHYSADDR=array [0..] MAXLEN_PHYSADDR - 1 Byte,
MIB_IFDESCR=array of Char [0.. MAXLEN_IFDESCR - 1].
PMIB_IFROW=^ MIB_IFROW;
MIB_IFROW=the packed record
WszName: array [0.. MAX_INTERFACE_NAME_LEN - 1] of WCHAR;
DwIndex,
DwType,
DwMtu,
DwSpeed,
DwPhysAddrLen: DWORD;
BPhysAddr: MIB_PHYSADDR;
DwAdminStatus,
DwOperStatus,
DwLastChange,
DwInOctets,
DwInUcastPkts,
DwInNUcastPkts,
DwInDiscards,
DwInErrors,
DwInUnknownProtos,
DwOutOctets,
DwOutUcastPkts,
DwOutNUcastPkts,
DwOutDiscards,
DwOutErrors,
DwOutQLen,
DwDescrLen: DWORD;
BDescr: MIB_IFDESCR;
end;
PMIB_IFTABLE=^ MIB_IFTABLE;
MIB_IFTABLE=the packed record
DwNumEntries: DWORD;
Table: array [0.. 0] of MIB_IFROW;
end;
TAdapterStatus=record
DwType,
DwOperStatus: DWORD;
BDescr: MIB_IFDESCR;
end;
TAdapterStatuses=array of TAdapterStatus;
The function GetIfTable (pIfTable: PMIB_IFTABLE; PdwSize: PULONG; BOrder: BOOL) : dwords.
Stdcall; External 'iphlpapi. DLL';
The function GetAdapterTypeString (const dwType: DWORD) : string;
The function GetGetAdapterStatusString (const dwOperStatus: DWORD) : string;
Procedure ScanAdapters (var AdapterStatuses: TAdapterStatuses);
Implementation
Var
DwSize: DWORD;
PMibIfTable: PMIB_IFTABLE;
The function GetAdapterTypeString (const dwType: DWORD) : string;
The begin
Case dwType of
MIB_IF_TYPE_OTHER: Result:='other';
MIB_IF_TYPE_ETHERNET: Result:='Ethernet;
MIB_IF_TYPE_TOKENRING: Result:='token ring;
FDDI MIB_IF_TYPE_FDDI: Result:=' ';
MIB_IF_TYPE_PPP: Result:='PPP';
MIB_IF_TYPE_LOOPBACK: Result:='loop';
MIB_IF_TYPE_SLIP: Result:='SLIP';
end;
end;
The function GetGetAdapterStatusString (const dwOperStatus: DWORD) : string;
The begin
Case dwOperStatus of
MIB_IF_OPER_STATUS_NON_OPERATIONAL: Result:='drops';
MIB_IF_OPER_STATUS_UNREACHABLE: Result:='inaccessible;
MIB_IF_OPER_STATUS_DISCONNECTED: Result:='disconnect';
MIB_IF_OPER_STATUS_CONNECTING: Result:='connection';
MIB_IF_OPER_STATUS_CONNECTED: Result:='connected';
MIB_IF_OPER_STATUS_OPERATIONAL: Result:='connected';
end;
end;
Procedure ScanAdapters (var AdapterStatuses: TAdapterStatuses);
Var
DwRetVal: DWORD;
Num, I: Longint;
The begin
DwRetVal:=GetIfTable (pMibIfTable @ dwSize, False);
If dwRetVal=NO_ERROR then
The begin
Num:=pMibIfTable ^. DwNumEntries;
If Length (AdapterStatuses) & lt;> Num then
SetLength (AdapterStatuses, num);
For I:=Low (AdapterStatuses) to High (AdapterStatuses) do
The begin
DwType AdapterStatuses [I]=pMibIfTable ^. Table [I] dwType;
DwOperStatus AdapterStatuses [I]=pMibIfTable ^. Table [I] dwOperStatus;
BDescr AdapterStatuses [I]=pMibIfTable ^. Table [I] bDescr;
end;
end;
end;
Initialization
GetIfTable (nil, @ dwSize, False);
GetMem (pMibIfTable dwSize);

Finalization
FreeMem (pMibIfTable);
End.




http://blog.csdn.net/avan_lau/article/details/17118619

http://www.delphitop.com/html/wangluo/190.html

CodePudding user response:

Upstairs online origin, no Dll, not available,

CodePudding user response:

Xie ask

Indeed many functions are not under 64 eggs with

The following code can only identify enabled network card Windows 7 64 - bit available

 
The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls CheckLst;

Const
MAX_HOSTNAME_LEN=128; {the from IPTYPES. H}
MAX_DOMAIN_NAME_LEN=128;
MAX_SCOPE_ID_LEN=256;
MAX_ADAPTER_NAME_LENGTH=256;
MAX_ADAPTER_DESCRIPTION_LENGTH=128;
MAX_ADAPTER_ADDRESS_LENGTH=8;

Type
TIPAddressString=array [0.. 4 * 4-1] of Char.
PIPAddrString=^ TIPAddrString;
TIPAddrString=Record
Next: PIPAddrString;
IPAddress: TIPAddressString;
IPMask: TIPAddressString;
Context: Integer;
end;

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related