Jump to content

Network Interface Info, Statistics, and Traffic


Ascend4nt
 Share

Recommended Posts

Updated today - version 3 (by my reckoning)!  This is now a full fledged Network Interface Information and Statistics UDF module.

2013-07-06:

 Added: Much more Adapter Information

 Changed: Example is now separate from the UDF

 Fixed some minor issues here and there

 Changed: Global Handle to IPHLPAPI.DLL is now contained in the UDF and used to speed up function calls

 Misc. Other fixes I didn't keep track of!

See 1st post, which is now a bit more detailed

 

Nice Update..

Work Perfectly..

How To Convert Splash Text

$sSplashText &= StringFormat("Data (Octets/Bytes): Recvd = %10u | Sent = %10u", $aNIEntryInfo[10], $aNIEntryInfo[16]) & @CRLF

To Create Label??

PLease,Give Me Example..

Thank's B4..

Link to comment
Share on other sites

How To Convert Splash Text

$sSplashText &= StringFormat("Data (Octets/Bytes): Recvd = %10u | Sent = %10u", $aNIEntryInfo[10], $aNIEntryInfo[16]) & @CRLF

To Create Label??

PLease,Give Me Example..

Thank's B4..

setengahglia,

See GUICreate, GUICtrlCreateLabel, etc.  It's not too hard creating a GUI, but very tedious and time consuming, which is why I don't bother with it for most examples.

By the way, I'd still like to know what kind of exit code you are getting when that modem is disconnected.  I'd like to document it and perhaps check for it.

Everyone else:

I'm also considering allowing for return of adapters that aren't enabled, and allowing filters for the type of adapters returned for the main functions. (in the future)  I'd appreciate it if anyone let me know what kind of adapters are popping up that they'd rather not see.  The 'type' and 'operational status' of them would help, or just give me a dump of the relevant console info.

Link to comment
Share on other sites

Okay, hopefully this will be the last update for a while.  Some things that were missing kept bugging me, so I added them in. Oh, and of course now there's a screenshot of the splash screen on Windows 8 - just to show how fugly that O/S is.. err, I mean to give an idea of what info is reported. o:)

2013-07-11:

 Changed: _Network_IPv4AdaptersInfoEx() now returns all IP's (if requested) and Address Masks

 Fixed: WSALastError call possible crash with non-array variable

 Changed: _Network_IPAllAddressTable() now allows 'down' status interfaces to be returned

 Added: Some comments on development, info on getting additional stats in the UDF

Link to comment
Share on other sites

  • 2 weeks later...

Help To Convert SplahText To Create Label

Ex My GUI

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "_NetworkStatistics.au3"

Local $aUDPStats, $aTCPStats, $aIPStats, $aICMPStats
Local $aUDPv6Stats, $aTCPv6Stats, $aIPv6Stats, $aICMPv6Stats
Local $aIPv4Adapters, $nAdapters
Local $aIPv4AddrTable, $aIPAllAddrTable, $nInterfaces, $aNIEntryInfo

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Network Meter", 212, 70, 192, 124)
$Label1 = GUICtrlCreateLabel("Sent", 16, 16, 26, 17)
$Label2 = GUICtrlCreateLabel("Receive", 16, 40, 44, 17)
$Label3 = GUICtrlCreateLabel($aNIEntryInfo, 72, 16, 88, 17)
$Label4 = GUICtrlCreateLabel($aNIEntryInfo, 72, 40, 88, 17)
$Label5 = GUICtrlCreateLabel("kb", 184, 16, 16, 17)
$Label6 = GUICtrlCreateLabel("kb", 184, 40, 16, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Thanks Before..

Link to comment
Share on other sites

You have to understand that $aNIEntryInfo, at least in my example, returns an array of 22 elements. You can't just create a single label with an array - it has to be a single element ($aNIEntryInfo[6] for example).

If you want to display all 22 elements? You need 22 labels.  Since the # of interfaces varies with machine, you'd probably want to dynamically size the GUI.. or use some type of editbox maybe?  I haven't thought that much through.

But anyway.. if you really need help with GUI creation, check the Help files, GUI examples, and GUI help forums as well as the General Help forum.  You can extrapolate the information you need from my example, or the headers for the functions.

Link to comment
Share on other sites

Ascend4nt:

First, i need to say something to you:  Thanks!! A lot!! 

In the last week i was looking for a script that show me the IPv4 of a PC in a Windows BOX. i do it before using cmd/bat and compiling to an .exe file. But i was looking for a simple script in vbs or something like that. But later i finded AUTOIT searching with google and reading this thread. I start reading, a lot of tutorials, the help, etc... and i enter to this world of Autoit and now im very happy.

I downloaded, and in doing test and programming (but with old knowledge, because 20 years ago i do basic and pascal only, and right now i dont remember almost nothing of that languages). 

I do my first simple script with AutoIt that shows common data for a PC (name, username, disk free space, Ip, etc).. and right now i want to put your script as a button in my little Pc Information tool. Right now i have problems, because you have a function in your example script and i put your script into mine as a function. So the ESC for exit doesn't work. The button works fine, and trigger your example anyways. I will continue to looking and reading, etc, so i will learn more and more and i will fix this little problem that i have, but i need to said thanks to you.

Maybe sounds lame, but you give me, testing with your script, the push that i need to start programming and using Autoit, Koda, Scite and a lot more.

Thanks a lot and sorry for my english, I have only three days with Autoit, but its seams wonderfull to use.

Link to comment
Share on other sites

zartrix, that's awesome to hear!  I feel humbled. :)   But honestly, I'm just one of many excellent programmers that share their work here (and advice) with others.  Hmm.. I suppose I just gave myself a sideways compliment.. okay, maybe I'm not excellent, but I do make excellent sautéed garlic chicken breast!

Anyway, welcome to the community - its by far one of the most knowledgeable and helpful programmer communities around (even among higher level languages)

Link to comment
Share on other sites

  • 2 weeks later...

Can't get the download/upload speed with my UDF?  Odd.. I wonder why I would have left that out.  Oh.. maybe because it's the reason the UDF was created in the first place :mad2:

Run the example. Look at the splash screen.  Does that give you any ideas?  Or have a look at the Console output to see the plethora of information you can get..  if you can't take that information and do something with it, I don't think I can help you.  Everything is literally right there

Link to comment
Share on other sites

Sorry i didnt look deap enough.  but i just checked out your sig and saw the performance counters in windows and it has exactly what im looking for. however, i dont know which pieces of code i need to reproduce what you have created. i was just curious if you could help me out with trying to grab the info from the counter name Datagrams/sec under the IPv4 section. I know its asking alot but i honestly just need that one piece of info and i can make the rest of the program. just thought id come to you first since you seem to be the expert on the matter.

Link to comment
Share on other sites

Well, if you want to go with Performance Counters, thats up to you.  I've been creating alternatives to that since a number of people seem to have them disabled on their PC's.  Normally, I'd answer questions in that thread about the counters, but for now I'll just give you the start of what you'd do (note - no error checking):

_PDH_Init()
Local $hQuery=_PDH_GetNewQueryHandle()
Local $hCounter=_PDH_AddCounter($hQuery,"::546\438\")  ; English: \IPv4\Datagrams/sec
_PDH_UpdateCounter($hQuery,$hCounter)
Sleep(250)
; Main Loop
While $bNotDone
$iCounterValue = _PDH_UpdateCounter($hQuery,$hCounter)
Sleep(500)
WEnd
_PDH_FreeQueryHandle($hPDHQuery)
_PDH_UnInit()

 

If you choose not to use Performance Counters, this is all you need to get the IPv4 Datagrams received & sent with the Network Stats UDF:

$aIPStats   = _Network_IPStatistics()
; Received = $aIPStats[2], Sent = $aIPStats[9]

The per-second thing is a matter of calculating delta between two readings in a second. Simple as that

Link to comment
Share on other sites

If you choose not to use Performance Counters, this is all you need to get the IPv4 Datagrams received & sent with the Network Stats UDF:

$aIPStats   = _Network_IPStatistics()
; Received = $aIPStats[2], Sent = $aIPStats[9]

The per-second thing is a matter of calculating delta between two readings in a second. Simple as that

 

thank you thank you! this is the piece of info i was looking for. this is very helpful. my script wouldnt be possible without your UDF so for that, i thank you :)

Link to comment
Share on other sites

  • 1 month later...

Wow! great UDF!

doing some tests, it seems to me that the function _Network_IPv4AddressTable () returns a wrong value of broadcast.

at returned array  index 3 ([$i][3] = Broadcast Address) I get 1.0.0.0 on all rows (tested on WIN XP and WIN 7 x64), but this is not a value of broadcast.

has anyone else experienced this?

Thanks

EDIT:

for example, see column 3 here  from the returned array:

#include "_NetworkStatistics.au3"
#include <array.au3>

Local $net =  _Network_IPv4AddressTable()

; Returns:
;  Success: Array of Interfaces info, @extended = # of Interfaces

;   [$i][2] = Subnet Mask #
;   [$i][3] = Broadcast Address #
;   [$i][4] = Max Reassembly Size for Recvd Datagrams
;   [$i][5] = Address Type/State
;       MIB_IPADDR_PRIMARY      = 0x01
;       MIB_IPADDR_DYNAMIC      = 0x04
;       MIB_IPADDR_DISCONNECTED = 0x08
;       MIB_IPADDR_DELETED      = 0x40
;       MIB_IPADDR_TRANSIENT    = 0x80

if not @error Then
    _ArrayDisplay($net)
EndIf
Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 2 months later...

Better late than never to respond?  That Broadcast address (1.0.0.0) is what I get with both command-line Microsoft utilities as well as the Windows API, so its really nothing to do with my script.

Link to comment
Share on other sites

Hi Ascend4nt, thanks for your reply!
this is a strange kind of broadcast address. I really do not know what kind of broadcast is this.
perhaps is another type of broadcast of the one that I know.

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 2 years later...

It is a really great udf. Thank you very much a lot!

Could you please provide a short example,  Say I have a process PID 4645, and it has connections to some IP's, Can I get the list of these connections (tcp, udp?)

 

Great thanx in advance!

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...