Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Network interface
#1
Hi Gintaras, hi all,

is there a way, knowing an network interface name, to "block" it, I mean stop it from receiving/sending bits, or if not, to disable it?

I try with

#compile __CPerformanceCounter
CPerformanceCounter c


Thanks.
#2
stackoverflow has some answers.
https://www.google.com/search?q=stackov ... +interface
#3
ok, will look. TY
#4
is Win32_NetworkAdapter class available through QM natively?
#5
Macro WMI - network connections - list, disable, enable
Code:
Copy      Help
;note: run as administrator.

out

def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32

IDispatch wmi._getfile("winmgmts:")
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL" @ wbemFlagReturnImmediately|wbemFlagForwardOnly)

IDispatch x
foreach x col
,;out x.NetConnectionId
,str name=x.Name
,out name
,if name="Realtek PCIe GBE Family Controller"
,,x.Disable
,,mes "Now should be disabled. Click OK to enable again."
,,x.Enable
,,;break
#6
was playing with this, that enumerates network interfaces

typelib WbemScripting {565783C6-CB41-11D1-8B02-00600806D9B6} 1.1

WbemScripting.SWbemServices objWMIService._getfile("winmgmts:")
WbemScripting.SWbemObjectSet colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL ","WQL",WbemScripting.wbemFlagReturnImmediately|WbemScripting.wbemFlagForwardOnly,0)
;"SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL"
WbemScripting.SWbemObject objProcess
foreach objProcess colProcesses
,out objProcess.Properties_.Item("Name" 0).Value

will try yours instead...
#7
Tweaked, runned, Perfect, wow you're the man!!!!
#8
to carry on implementation on my own (if i can), where can i find IDispatch x reference for x members availability?

I search to test status, and x.Status does not seem to exist...
#9
https://msdn.microsoft.com/en-us/library...S.85).aspx
#10
Should have guessed, you just answered my first question...great

Maybe integrated in next QM version
#11
BUT:

str name=x.NetConnectionID

gives

Error (RT) in <open ":3264: /324">Stoppe_VPN: unknown member

and it's the item right after Name...

Why?
#12
In my first example was "SELECT Name ...". If want more members, use "SELECT * ...".
#13
This also works.

Macro Network connections - disable, enable
Code:
Copy      Help
;note: run as administrator.

if(RunConsole2("netsh interface set interface ''Ethernet 3'' admin=disable")) end "failed"
mes "Now should be disabled. Click OK to enable again."
if(RunConsole2("netsh interface set interface ''Ethernet 3'' admin=enable")) end "failed"
#14
damned, i missed it...thanks
#15
uint16 = Long in QM?
#16
word
#17
**From MSDN

NetConnectionStatus
Data type: uint16
Access type: Read-only

word i=x.NetConnectionStatus

Error (RT) type mismatch <help #IDP_ERR>?
#18
Possibly its type is VT_NULL (1). It means empty, and error if trying to convert to some other type.

VARIANT v=x.NetConnectionStatus
out v.vt

On my PC NetConnectionStatus gives word 2 or 7. But Status is VT_NULL.
#19
does the trick, ty
#20
last one (for the moment)

Is a function created at QM launch and constantly monitoring an network interface for some properties is "heavy" for the system,
or is it better to have a toolbar with a procedure attached more efficient??? and for the latter, what is the message to wait for (something like WM_ADAPTERSTATUSCHANGED)?

Because I already have one toolbar used for monitoring some windows events already running...but don't want to overload it...
#21
Function (thread) itself isn't heavy. Depends on what it does and how frequently.

Message - use OutWinMsg in a window/dialog/toolbarhook procedure to see received messages.
#22
ok, will do..

Thanks for all again
#23
i struggle with getting information, as i have many type mismatches when trying to retreive
parameter information, even if i give return variable the right type (uint16, string etc)

How to debug error to find the correct variable type to give for return?

class Win32_NetworkAdapter : CIM_NetworkAdapter
{
string AdapterType;
uint16 AdapterTypeID;
boolean AutoSense;
uint16 Availability;
string Caption;
uint32 ConfigManagerErrorCode;
boolean ConfigManagerUserConfig;
string CreationClassName;
string Description;
string DeviceID;
boolean ErrorCleared;
string ErrorDescription;
string GUID;
uint32 Index;
datetime InstallDate;
boolean Installed;
uint32 InterfaceIndex;
uint32 LastErrorCode;
string MACAddress;
string Manufacturer;
uint32 MaxNumberControlled;
uint64 MaxSpeed;
string Name;
string NetConnectionID;
uint16 NetConnectionStatus;
boolean NetEnabled;
string NetworkAddresses[];
string PermanentAddress;
boolean PhysicalAdapter;
string PNPDeviceID;
uint16 PowerManagementCapabilities[];
boolean PowerManagementSupported;
string ProductName;
string ServiceName;
uint64 Speed;
string Status;
uint16 StatusInfo;
string SystemCreationClassName;
string SystemName;
datetime TimeOfLastReset;
};
#24
foreach x col
str name=x.Name
out name

TAP-Windows Adapter V9
Microsoft Kernel Debug Network Adapter
Qualcomm Atheros AR8171/8175 PCI-E Gigabit Ethernet Controller (NDIS 6.30)
Carte réseau Broadcom 802.11ac
Broadcom NetXtreme Gigabit Ethernet
Microsoft Wi-Fi Direct Virtual Adapter
Bluetooth Device (RFCOMM Protocol TDI)
Bluetooth Device (Personal Area Network)
Microsoft Hosted Network Virtual Adapter
WAN Miniport (SSTP)
WAN Miniport (IKEv2)
WAN Miniport (L2TP)
WAN Miniport (PPTP)
WAN Miniport (PPPOE)
WAN Miniport (IP)
WAN Miniport (IPv6)
WAN Miniport (Network Monitor)
Realtek USB GbE Family Controller


foreach x col
str name=x.Name
out name
out x.NetConnectionId

Microsoft Kernel Debug Network Adapter
Error (RT) in <open ":168: /336">: 0x80020005, type mismatch
#25
Macro WMI - network connections - list, disable, enable
Code:
Copy      Help
,VARIANT v=x.NetConnectionId
,out v.vt
Then look in QM help topic "VARIANT members table".

If some vt are 0 or 1, look in SELECT, it should be "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL". In my first example probably was without "WHERE NetConnectionId != NULL".
#26
lol, pretty cryptic, but I missed I must output VARIANT v.vt, not VARIANT v, learned that at least
#27
ok, i did get some improvements using VARIANT
Some fill correct datas

v=x.Name
out "Name: %S" v.pbstrVal
v=x.AdapterType
out "Type: %S" v.pbstrVal
v=x.AdapterTypeID
out "AdapterTypeID: %i" v.uintVal
v=x.Availability
out "Availability: %i" v.uintVal

some don't (like Status).

1. When v.vt = 1, means I can't access data from the variable (as x.Status)? any of variable type does generate type mismatch
2. Some are date (as x.TimeOfLastReset), using v.date is giving 00:00:00

ideas?
#28
How to deal with arrays?

one property is this

string NetworkAddresses[];

IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE IPEnabled=''TRUE''" ,@,IFlags)
foreach x col
foreach v x.NetworkAddresses
out v.vt

does not work....
#29
On my PC it is VT_NULL. If it would not be null, assign it to an ARRAY(str) variable.

Macro Macro272
Code:
Copy      Help
;note: run as administrator.

out

def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32

IDispatch wmi._getfile("winmgmts:")
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL" @ wbemFlagReturnImmediately|wbemFlagForwardOnly)

IDispatch x
foreach x col
,str name=x.Name
,out name
,VARIANT v=x.NetworkAddresses
,sel v.vt
,,case VT_ARRAY|VT_BSTR
,,ARRAY(str) a=x.NetworkAddresses
,,int i
,,for i 0 a.len
,,,out a[i]
,,
,,case VT_NULL
,,out "no data, sorry"
,,
,,case else
,,end "what?!"
,,
#30
TAP-Windows Adapter V9
no data, sorry
Qualcomm Atheros AR8171/8175 PCI-E Gigabit Ethernet Controller (NDIS 6.30)
no data, sorry
Carte réseau Broadcom 802.11ac
no data, sorry
Broadcom NetXtreme Gigabit Ethernet
no data, sorry


Forum Jump:


Users browsing this thread: 1 Guest(s)