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

i'd like to trigger an action when my internet connection is not used for some times or when connection is not used for
a certain time.

In fact, my web downloader can turn off my laptop when downloads are completed, but if for some reasons some are
stalled, ie still active but no downloading is done for some reason, it does not do it.

Any ideas to monitor data for an interface (can be a virtual one as i use a VPN).

Thanks
#2
-
#3
mmm....Is it language related?
None of the interfaces is found on my computer.

Should \Network Interface(*) typed in a French equivalent, and where to find it?
#4
Run perfmon, there you can find available counters.


Attached Files Image(s)
   
#5
tried that many ways, no way...

i'll find a workaround.
#6
Macro Macro2108
Code:
Copy      Help
RunConsole2 "netstat -e"
#7
yep, seems a good idea.
was thinking about monitoring download folders size too, and some other stuff.
thanks for the input.

FIW, in my french W8 laptop, there is something like
"interface card activity by processor"
that replace "network interface" in your screenshot.
and launching perfmon casts an error saying it can't add counters (inclosed image)..maybe can help you understand the failure.

Seems to mess QM....


Attached Files Image(s)
   
#8
GetIfTable gets similar info as netmon.

Macro test get internet bytes received with GetIfTable
Code:
Copy      Help
type MIB_IFROW @wszName[256] dwIndex dwType dwMtu dwSpeed dwPhysAddrLen !bPhysAddr[8] dwAdminStatus dwOperStatus dwLastChange dwInOctets dwInUcastPkts dwInNUcastPkts dwInDiscards dwInErrors dwInUnknownProtos dwOutOctets dwOutUcastPkts dwOutNUcastPkts dwOutDiscards dwOutErrors dwOutQLen dwDescrLen !bDescr[256]
type MIB_IFTABLE dwNumEntries MIB_IFROW'table[1]
dll iphlpapi #GetIfTable MIB_IFTABLE*pIfTable *pdwSize bOrder

str sb
int i n=100*sizeof(MIB_IFTABLE)
rep
,MIB_IFTABLE* t=sb.all((n+10)*sizeof(MIB_IFTABLE))
,int hr=GetIfTable(t &n 0); if(!hr) break
,if(hr!=ERROR_INSUFFICIENT_BUFFER) end _s.dllerror("" "" hr)

out
for i 0 t.dwNumEntries
,MIB_IFROW& r=t.table[i]
,int kbReceived=r.dwInOctets/1024
,if(kbReceived=0) continue
,out F"{kbReceived} KB received and {r.dwOutOctets/1024} KB sent by {&r.bDescr%%s} ({&r.wszName%%S})"
#9
much better, this one will really help.
i'll manage the remaining code on my own.

TY, excellent support as usual.
#10
Same with GetIfTable2. Unavailable on XP.
Macro test get internet bytes received with GetIfTable2
Code:
Copy      Help
;type MIB_IFROW @wszName[256] dwIndex dwType dwMtu dwSpeed dwPhysAddrLen !bPhysAddr[8] dwAdminStatus dwOperStatus dwLastChange dwInOctets dwInUcastPkts dwInNUcastPkts dwInDiscards dwInErrors dwInUnknownProtos dwOutOctets dwOutUcastPkts dwOutNUcastPkts dwOutDiscards dwOutErrors dwOutQLen dwDescrLen !bDescr[256]
;type MIB_IFTABLE dwNumEntries MIB_IFROW'table[1]
;dll iphlpapi #GetIfTable MIB_IFTABLE*pIfTable *pdwSize bOrder
type NET_LUID_LH %Value []%Info
type MIB_IF_ROW2 NET_LUID_LH'InterfaceLuid InterfaceIndex GUID'InterfaceGuid @Alias[257] @Description[257] PhysicalAddressLength !PhysicalAddress[32] !PermanentPhysicalAddress[32] Mtu Type TunnelType MediaType PhysicalMediumType AccessType DirectionType !InterfaceAndOperStatusFlags OperStatus AdminStatus MediaConnectState GUID'NetworkGuid ConnectionType %TransmitLinkSpeed %ReceiveLinkSpeed %InOctets %InUcastPkts %InNUcastPkts %InDiscards %InErrors %InUnknownProtos %InUcastOctets %InMulticastOctets %InBroadcastOctets %OutOctets %OutUcastPkts %OutNUcastPkts %OutDiscards %OutErrors %OutUcastOctets %OutMulticastOctets %OutBroadcastOctets %OutQLen
type MIB_IF_TABLE2 NumEntries MIB_IF_ROW2'Table[1]
dll iphlpapi #GetIfTable2 MIB_IF_TABLE2**Table
dll iphlpapi #GetIfTable2Ex Level MIB_IF_TABLE2**Table
dll iphlpapi FreeMibTable !*Memory

MIB_IF_TABLE2* t
int hr=GetIfTable2(&t); if(hr) end _s.dllerror("" "" hr)

out
int i
for i 0 t.NumEntries
,MIB_IF_ROW2& r=t.Table[i]
,int kbReceived=r.InOctets/1024
,if(kbReceived=0) continue
,out F"{kbReceived} KB received and {r.OutOctets/1024} KB sent by {&r.Description%%S}"

FreeMibTable t
#11
This one is just perfect, thanks.
Maybe you could put it natively in QM
#12
Reviving for precision.

1) how to use a function giving result a MIB_IF_TABLE2* variable, i can't get this to work in my code


MIB_IF_TABLE2* t=ActiviteInternet
or
ActiviteInternet(MIB_IF_ROW2* r)
whatever the best



derivated from:
Function ActiviteInternet
Code:
Copy      Help
type NET_LUID_LH %Value []%Info
type MIB_IF_ROW2 NET_LUID_LH'InterfaceLuid InterfaceIndex GUID'InterfaceGuid @Alias[257] @Description[257] PhysicalAddressLength !PhysicalAddress[32] !PermanentPhysicalAddress[32] Mtu Type TunnelType MediaType PhysicalMediumType AccessType DirectionType !InterfaceAndOperStatusFlags OperStatus AdminStatus MediaConnectState GUID'NetworkGuid ConnectionType %TransmitLinkSpeed %ReceiveLinkSpeed %InOctets %InUcastPkts %InNUcastPkts %InDiscards %InErrors %InUnknownProtos %InUcastOctets %InMulticastOctets %InBroadcastOctets %OutOctets %OutUcastPkts %OutNUcastPkts %OutDiscards %OutErrors %OutUcastOctets %OutMulticastOctets %OutBroadcastOctets %OutQLen
type MIB_IF_TABLE2 NumEntries MIB_IF_ROW2'Table[1]
dll iphlpapi #GetIfTable2 MIB_IF_TABLE2**Table
dll iphlpapi #GetIfTable2Ex Level MIB_IF_TABLE2**Table
dll iphlpapi FreeMibTable !*Memory

MIB_IF_TABLE2* t
int hr=GetIfTable2(&t); if(hr) end _s.dllerror("" "" hr)

for _i 0 t.NumEntries
,MIB_IF_ROW2& r=t.Table[_i]
,if(strcmp("my-adapter" F"{&r.Description%%S}")!=0) continue
,else break
FreeMibTable t
ret r


So I could get a MIB_IF_ROW2 pointer as result, and use initialized variable for specific adapter at QM start.

2)

isn't r.ReceiveLinkSpeed supposed returning download speed (like 410 kb/s)??
does not seem to work.
#13
Function ActiviteInternet
Code:
Copy      Help
;/
function! $mibName MIB_IF_ROW2&mibInfo

;If finds mibName, stores its info in variable mibInfo and returns 1. Else returns 0.

;EXAMPLE
;#compile __api63429 ;;MIB_IF_ROW2 declared there
;MIB_IF_ROW2 r
;if ActiviteInternet("my-adapter" r)
,;out F"{&r.Description%%S}"


MIB_IF_TABLE2* t
int hr=GetIfTable2(&t); if(hr) end _s.dllerror("" "" hr)

int found
for _i 0 t.NumEntries
,MIB_IF_ROW2& r=t.Table[_i]
,;out F"{&r.Description%%S}"
,if(strcmp(mibName F"{&r.Description%%S}")!=0) continue
,mibInfo=r
,found=1; break
FreeMibTable t
ret found
Function __api63429
Code:
Copy      Help
type NET_LUID_LH %Value []%Info
type MIB_IF_ROW2 NET_LUID_LH'InterfaceLuid InterfaceIndex GUID'InterfaceGuid @Alias[257] @Description[257] PhysicalAddressLength !PhysicalAddress[32] !PermanentPhysicalAddress[32] Mtu Type TunnelType MediaType PhysicalMediumType AccessType DirectionType !InterfaceAndOperStatusFlags OperStatus AdminStatus MediaConnectState GUID'NetworkGuid ConnectionType %TransmitLinkSpeed %ReceiveLinkSpeed %InOctets %InUcastPkts %InNUcastPkts %InDiscards %InErrors %InUnknownProtos %InUcastOctets %InMulticastOctets %InBroadcastOctets %OutOctets %OutUcastPkts %OutNUcastPkts %OutDiscards %OutErrors %OutUcastOctets %OutMulticastOctets %OutBroadcastOctets %OutQLen
type MIB_IF_TABLE2 NumEntries MIB_IF_ROW2'Table[1]
dll iphlpapi #GetIfTable2 MIB_IF_TABLE2**Table
dll iphlpapi #GetIfTable2Ex Level MIB_IF_TABLE2**Table
dll iphlpapi FreeMibTable !*Memory

2. Look in MSDN Library.
#14
Thanks for 2nd input, was what i was prepared to ask for, MIB_IF_ROW2& r variable handling.

Generic way to pass pointer and references to functions and result, been struggling hard for this too.

For 2nd answer, i supposed it means i'm right to use it for the purpose, and you don't know too why it doesn't work.

Any idea to get current downlod speed for an interface?

i found a freeware program name awatch that does it, and want to mimic it (i try to use QM to use the fewer third party programs
as i can, as soon as i can code some functionalities I need.

See screenshot.


Attached Files Image(s)
   
#15
Quote:Any idea to get current downlod speed for an interface?
Previous example shows bytes received, r.dwInOctets. To calculate download speed, run the code eg every 1 s...
It works on my PC. I just don't know what adapters are true, on my PC shows maybe 20, etc.
#16
Ok, so download speed is in fact the result of an equation, data/interval. i get it now, I thought the
structure had a direct variable for this.

I'll do it later. Thanks.
#17
what is the difference calling the function

function! $mibName MIB_IF_ROW2&mibInfo

a) if ActiviteInternet("my-adapter" r)
b) if ActiviteInternet("my-adapter" &r)

both work but I wonder the differences between the two syntaxes....
#18
No difference. In both cases it passes address of the variable (physically).
If using pointer (ROW2*mibInfo), then need &.
Physically ROW2&mibInfo and ROW2*mibInfo are the same.
#19
ok
#20
is it possible to make a trigger from a variable result?
instead of an infinite rep loop function?

for instance, r.MediaConnectState could be a trigger; an action can be done
on certain value.
#21
no
#22
I was sure of that...

Anyway, i put a process trigerred function on my VPN program, and start/stop monitoring
is handled by it, pretty convenient.


Forum Jump:


Users browsing this thread: 2 Guest(s)