Sign in to follow this  
Followers 0
sulfurious

NIC current activity function - needed

4 posts in this topic

Greetings.

My latest project requires some network activity. What I am trying to do is basically this:

Provide script that give user the current options for downloadable files > that depends on >

whether or not the server is currently giving one of these files to another user.

I have looked at WMI, but have not found one yet that looks to a remote computer (the server) and checks to see if there is network activity of say above 15% (which I deem to be a safe percentage of the available bandwidth).

I have some large files to transfer depending on users schedules, so 2 may wish to do so at the same time, and I hope to limit it to 1 at a time. In that past I have just created a text file that acts as a boolean for the script, which works great until the app decides to crash and then leaves that text file in place instead of deleting it properly.

Any ideas on either a vbs, wmi or autoit or dll that can achieve this?

Thanks,

Sul

Share this post


Link to post
Share on other sites



@sulfurious

Something I picked up on the way.

This can easily be converted to a remote bandwith meter uwing the same WMI concepts

#include <GUIConstants.au3>

GUICreate("Lod3n's Bandwidth Monitor",220,100,0,0,-1,$WS_EX_TOOLWINDOW)

$label1 = GUICtrlCreateLabel ( "Waiting for data...", 10, 5,200,20)
$progressbar1 = GUICtrlCreateProgress (10,20,200,20,$PBS_SMOOTH)

$label2 = GUICtrlCreateLabel ( "Waiting for data...", 10, 50,200,20)
$progressbar2 = GUICtrlCreateProgress (10,65,200,20,$PBS_SMOOTH)

GUISetState ()

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

$inmax = 0
$outmax = 0

$lastin = 0
$lastout = 0

while 1
    ;$colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    
    If IsObj($colItems) then
        For $objItem In $colItems
            $newin = $objItem.BytesReceivedPersec
            $newout = $objItem.BytesSentPersec
            
            ;new realtime counter code...
            if $lastin = 0 and $lastout = 0 Then
                $lastin = $newin
                $lastout = $newout
            endif
            $in = $newin - $lastin
            $out = $newout - $lastout
            $lastin = $newin
            $lastout = $newout

            if $in <> 0 and $out <> 0 Then
                if $in > $inmax then $inmax = $in
                if $out > $outmax then $outmax = $out
                
                $inP = int(($in / $inmax) * 100)
                $outP = int(($out / $outmax) * 100)
                ;$in = $in/1024
                ;$out = $out/1024         
                $intext = "Bytes In/Sec: " & int($in) & " [" &$inP & "% of record]" & @CRLF
                $outtext = "Bytes Out/Sec: " & int($out) & " [" &$outP & "% of record]" &@CRLF

                GUICtrlSetData ($progressbar1,$inP)
                GUICtrlSetData ($label1,$intext)
                GUICtrlSetData ($progressbar2,$outP)
                GUICtrlSetData ($label2,$outtext)
                
            EndIf
            ExitLoop ; I only care about the first network adapter, yo
        Next
    EndIf
   sleep(1000) ; bytes PER SECOND
   If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Regards,

ptrex

Share this post


Link to post
Share on other sites

@ptrex - Nice example. I looked at those WMI's in scriptomatic. I should have put them into a routine instead of just dumping output and viewing.

Works nice on localhost, see about remote now.

Thanks for code.

Sul

Share this post


Link to post
Share on other sites

Hmm. Seem to be at a standstill now.

I have a w2k advanced server sp4. No domain, just a workgroup. About 20 users, each with thier account, very few with anything other than standard user read write permission to thier shares and certain public shares. I have admin account.

Changing that script above to include the machine name "fileserver" or the ip, gives an error. Switching over to vbs and running with cscript produces the "GetObject" error of permission denied. Some research shows that I should be using something like this for alternate credentials

Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer _
    (strComputer, strNamespace, strUser, strPassword)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

While that does not throw the permission denied error, I'll be darned if I can actually attach to anything on that server and retrieve any echo's with it. It is like that moniker gets approved, but sort of screws the rest up. Been technetting for awhile now, and afraid I am no closer. Some references to Dcom permissions led me to inspect that, but seems users should have rights to read and execute but not write/edit. And my administrator status is wide open, so I don't see an issue there.

Is there anyone who has access to a 2k server sp4 that might be able to verify a connection string? MS website is so contorted it is about useless. Maybe someone knows of the .pdf or .chm that has the WMI DOM. Only thing MS seems to want to give me is I think CMI SDK, what they have labeled WMI SDK. I don't exactly want 395mb of that help file.

Any thoughts?

Sul

Share this post


Link to post
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
Sign in to follow this  
Followers 0