Jump to content

Example of Dynamic uTorrent Bandwidth limiter in VBScript


AltTab

Recommended Posts

Joined to share this code that i have been using on my computer that runs uTorrent and PlexApp. Also before sharing this code there is a behavior you should know about too. If you use uTorrents Schedule feature this WebUI setting limit will not affect the limits set by the scheduler. But for me after the scheduler changes back to Full Speed at 6PM then i have a scheduled task in windows that runs this vbscript that starts at 6 and repeats for 6 hours every 5 minutes. Doing this so when i want to watch streaming videos from the Roku's Plex or Ouya's XBMC I can while still using uTorrent.

on error resume next
'on error goto 0
'EDIT THESE VARIABLES
uTorrentIP="192.168.1.2" 'THIS MUST BE CHANGED TO MATCH YOUR uTORRENT CLIENT/NAS...WHATEVER IT IS!!!!
uTorrentPort="23177"
uTorrentServerID="admin"
uTorrentServerPW="admin"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim MyConnection, TheURL

sComputerName = "."
Set objWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\cimv2")
sQuery = "SELECT * FROM Win32_Process"
Set objItems = objWMIService.ExecQuery(sQuery)
'iterate all item(s)
isPlexTranscoding = False
For Each objItem In objItems
If UCase(objItem.Name) = "PLEXNEWTRANSCODER.EXE" Then
uLimit 300,25
isPlexTranscoding = True
Exit For
ElseIf UCase(objItem.Name) = "PLEXTRANSCODER.EXE" Then
uLimit 300,25
isPlexTranscoding = True
Exit For
Else
isPlexTranscoding = False
End If
Next

If isPlexTranscoding = False Then
dim objPing
dim objStatus
dim strComputer

strComputer="192.168.1.7" 'IP Address or Name
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")

For Each objStatus in objPing
If IsNull(objStatus.ReplySize) Then
'WScript.Echo "computer is offline"
'If isPlexTranscoding = False Then
uLimit 0,0
Else
'WScript.Echo "computer is online"
uLimit 300,25
End If
Next

Set objPing=Nothing
Set objStatus=Nothing
End If

Sub uLimit(dlrate,ulrate)
TOKEN = getTOKEN
TheURL="HTTP://"&uTorrentIP&":"&uTorrentPort&"/gui/?token="&TOKEN&"&action=setsetting&s=max_dl_rate&v="&dlrate&"&s=max_ul_rate&v="&ulrate
Set Http = CreateObject("MSXML2.XMLHTTP")
Http.Open "GET",TheURL,false
Http.Send
uTorrentResponse = Http.responseText
Set Http = Nothing
'msgbox uTorrentResponse
End Sub

Function getTOKEN
'GO FETCH AND PARSE THE A TOKEN FROM uTorrent
'TokenURL="HTTP://"&uTorrentServerID&":"&uTorrentServerPW&"@"&uTorrentIP&":"&uTorrentPort&"/gui/token.html"
TokenURL="HTTP://"&uTorrentIP&":"&uTorrentPort&"/gui/token.html"
Set xml = CreateObject("Microsoft.XMLHTTP")
'xml.Open "GET", TokenURL, False
xml.Open "GET", TokenURL, False, uTorrentServerID, uTorrentServerPW
xml.SEND
TokenPage = xml.responseText

StartTag="<div id='token' style='display:none;'>"
EndTag="</div>"
getTOKEN = ""
lArray = Split(TokenPage, StartTag)

If IsArray(lArray) Then
Extract = lArray(1)
lArray = Split(Extract, EndTag)
If IsArray(lArray) Then
getTOKEN = lArray(0)
Else
getTOKEN = ""
End If
End If
Set xml = Nothing

End Function

Link to comment
Share on other sites

  • 9 months later...

Just wanted to say thank you for this script! I didn't want to have to switch the router out at my parent's house for one that supported QoS if I didn't need to. I realized you have one computer torrenting and another computer serving plex so I saw to change both addresses in the script.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...