Skip to content

Instantly share code, notes, and snippets.

@kylestev
Created May 23, 2012 03:37
Show Gist options
  • Select an option

  • Save kylestev/2773128 to your computer and use it in GitHub Desktop.

Select an option

Save kylestev/2773128 to your computer and use it in GitHub Desktop.
Fiddler Netflix blocker using HostList class
import Fiddler;
class Handlers {
static var nopeGif = "<img src=\"http://i.imgur.com/OLRXz.gif\" />";
static var blocked = "<html><head><title>Blocked</title></head><body><h2>Blocked</h2><p>Stop using all my bandwidth!!</p><br />" + nopeGif + "</body></html>";
static var hostList = new HostList("*.netflix.com,*.nflximg.com");
static function OnBeforeRequest(oSession: Session) {
if (hostList.ContainsHost(oSession.hostname)) {
oSession["ui-bold"] = "true";
oSession["ui-color"] = "blue";
oSession.oRequest.FailSession(403, "Blocked", blocked);
}
}
}
@kylestev

Copy link
Copy Markdown
Author

I don't have anything against Netflix; heck I watch shows on there all the time. This is just a demonstration of the HostList class since I was unable to find any on the net and figured others could benefit.

@ericlaw

ericlaw commented Oct 31, 2012

Copy link
Copy Markdown

There's a subtle bug here, although it doesn't matter in your particular case. You should either use:

if (hostList.ContainsHost(oSession.host))

or

if (hostList.ContainsHostname(oSession.hostname))

Otherwise, rules that are constrained to particular ports won't work properly.

@kylestev

Copy link
Copy Markdown
Author

@ericlaw thanks! sorry I didn't see this until now. This was from back in high school when I was writing some sample rulesets to show the IT department what Fiddler could do for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment