Set clientIP for geolocation testing (GeoIP)

3 posts, 0 answers
  1. Pete
    Pete avatar
    2 posts
    Member since:
    Sep 2015

    Posted 24 Sep 2015 Link to this post

    I needed an easy way to change the clientIP of a request without having to set a custom break-point and add a header every time or use a proxy service - so I extended Fiddler with a custom rule and I thought I'd share that here for anyone else looking for something similar. I had a few locations that I specifically needed, so I created those as menu items in addition to adding a custom field.

    Open your CustomRules.js for modification - 

    Under class Handlers add:

    // Set clientIP
    // Modify the country names and IP address as appropriate, or simply use Custom and set the array value to 0

    RulesString("&Set clientIP", true)
    RulesStringValue(0,"Country Name 1", "0.0.0.0")
    RulesStringValue(1,"Country Name 2", "127.0.0.1")
    RulesStringValue(2,"Country Name 3", "​192.168.1.1")
    RulesStringValue(3,"&Custom...", "%CUSTOM%")
    public static var sClientIP: String = null;

     /* -- end class handlers --*/

     

    Under  OnBeforeRequest(oSession: Session) add:

    // Set clientIP
    if (null != sClientIP) {

        oSession.oRequest["clientIP"] = sClientIP; 
    }​

    Save the file and the new option will be added to your Rules menu - you can switch IP addresses with a click, and simply refresh the browser to effectively request the page with the assigned IP address.

  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 24 Sep 2015 Link to this post

    Thanks, Pete!

    To be clear, what this rule does is send a custom header named ClientIP with the specified value; your server might use this instead of the client's actual IP address. Some servers instead respect an X-Forwarded-For header instead.

    If the web page uses the HTML5 GeoLocation API, you should have a look at the AnyWhere ​extension for Fiddler. If you need true geolocation, you can use the GeoEdge menu in Fiddler.

    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Pete
    Pete avatar
    2 posts
    Member since:
    Sep 2015

    Posted 24 Sep 2015 in reply to Eric Lawrence Link to this post

    Thanks Eric! It's probably worth mentioning the tests were conducted on an internal (staging) web server, so you're right - millage may vary. :-)

    Aside - I found the documentation on custom rules to be very clear and helpful. I was pleasantly surprised how easy it was to extend the functionality and add a sub menu! It's been my experience that most dev documentation either makes a lot of assumptions or is completely inaccurate, so kudos for that! :)

Back to Top