This is a migrated thread and some comments may be shown as answers.

capture traffic with cmd?

10 Answers 1597 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Zsolt
Top achievements
Rank 1
Zsolt asked on 17 Nov 2015, 04:29 PM
I'm wondering if it's possible with line to start to recording specific hosts headers, save to file and stop it? How?

10 Answers, 1 is accepted

Sort by
0
Zsolt
Top achievements
Rank 1
answered on 17 Nov 2015, 06:50 PM
I managed to do a workaround with the  ,start,stop,dump functions. there is any  function where can dump/save to .txt file the selected (@host) sessions to any location? thanks
0
Eric Lawrence
Telerik team
answered on 17 Nov 2015, 10:44 PM
Hello, Zsolt--

I assume you've figured out that a command runner can use the ExecAction.exe program to invoke QuickExec commands inside Fiddler?

Those QuickExec commands simply invoke the OnExecAction handler inside your Fiddler Rules Script (Rules > Customize Rules...). If you examine the source of that function, you can see how you can add new commands that do anything you like, implemented in JScript.NET.

I'm not entirely clear on what you want your function to do, but you'll probably use the File.WriteAllText method (after adding import System.IO and System.Text to the list atop your script) to write a text file. You would get the list of Sessions in the Session list using FiddlerApplication.UI.GetAllSessions();

So, maybe something like:

   case "dumphosts":
       var arrSess: Fiddler.Session[] = FiddlerApplication.UI.GetAllSessions();
       var sbAllHosts: StringBuilder = new StringBuilder();
       for (var i = 0; i < arrSess.Length; i++)
       {
           sbAllHosts.AppendLine(arrSess[i].host);
       }
      File.WriteAllText("C:\\temp\\allHosts.txt", sbAllHosts.ToString());

    return true;


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
0
Zsolt
Top achievements
Rank 1
answered on 18 Nov 2015, 03:28 PM

Hi, Eric

Thanks for your reply it helps a lot! I'm trying to create my function however I'm struggling with it. What I'm trying to achieve is:
select the specified host's (param[1]) header and save it to a file(param[2]) and/or the command line would return it. Specifically I want to get the Cookies from it at the same format how it's showing at the Raw View. 

0
Zsolt
Top achievements
Rank 1
answered on 18 Nov 2015, 03:38 PM
I read the have doesn't work for me.How can I switch that on? Can't find it
0
Zsolt
Top achievements
Rank 1
answered on 18 Nov 2015, 03:46 PM
This forum really needs an edit button :D so actually intelliSense works but only if I specify the full length as FiddlerApplication.UI.andthefunctions come up here. I did import FiddlerApplication.UI; what am I missing? 
0
Eric Lawrence
Telerik team
answered on 18 Nov 2015, 05:34 PM
Hello, Zsolt--

It's hard to keep track of what your questions are. 

Intellisense in the FiddlerScript Editor is based on the capabilities of the underlying component; various "shorthand" objects (e.g. "UI") don't have Intellisense behaviors.

select the specified host's (param[1]) header and save it to a file(param[2]) and/or the command line would return it. Specifically I want to get the Cookies from it at the same format how it's showing at the Raw View.

I think you're saying you want to be able to do

    ExecAction.exe "dumpcookies example.com C:\temp\CookiesFromExample.txt"

...is that right?

You haven't mentioned whether you're looking for the REQUEST Cookie header or the RESPONSE Set-Cookie header?


  case "dumpcookies":
       var arrSess: Fiddler.Session[] = FiddlerApplication.UI.GetAllSessions();
       var sbAllCookies: StringBuilder = new StringBuilder();
       for (var i = 0; i < arrSess.Length; i++)
       { 
           if (arrSess[i].HostnameIs(sParams[0]))
           {
              // Get Cookie
              var sCookie = arrSess[i].RequestHeaders["Cookie"];
              if (!String.IsNullOrEmpty(sCookie)){
                 sbAllCookies.AppendLine(sCookie);
              }
       }
      File.WriteAllText(sParams[1], sbAllCookies.ToString());

    return true;





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
0
Zsolt
Top achievements
Rank 1
answered on 18 Nov 2015, 06:20 PM
Nice examples Eric! However, I realized I asked the question wrongly. I want to get the cookies of a specific not host. Sorry for it but your examples gave me enough knowledge to craft this:

for selecting I wanted to use the ? command which works if I do it in the but it isn't If I do through cmd?! How can I select the URL so after I can proceed with the  script?

case "savecookie":
        var Session = FiddlerApplication.UI.GetFirstSelectedSession();
        File.WriteAllText(sParams[1], Session.RequestHeaders["Cookie"].ToString());
        return true;
0
Accepted
Eric Lawrence
Telerik team
answered on 18 Nov 2015, 07:25 PM
You can just do this (remove the break if you want to allow multiple instances of the target URL):

  case "dumpcookies":
       var arrSess: Fiddler.Session[] = FiddlerApplication.UI.GetAllSessions();
       var sbAllCookies: StringBuilder = new StringBuilder();
       for (var i = 0; i < arrSess.Length; i++)
       { 
           if (arrSess[i].fullUrl == sParams[0])
           {
              // Get Cookie
              var sCookie = arrSess[i].RequestHeaders["Cookie"];
              if (!String.IsNullOrEmpty(sCookie)){
                 sbAllCookies.AppendLine(sCookie);
break;
              }
       }
      File.WriteAllText(sParams[1], sbAllCookies.ToString());

    return true;


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
0
Zsolt
Top achievements
Rank 1
answered on 18 Nov 2015, 07:51 PM
Eric you saved my day! I appreciate it! It works like !

Just add an extra closing curly bracket after the change sParams[0] to sParams[1] and sParams[1] to sParams[2] if somebody else wants to use it. 

I wasn't beware of the fullURL property
0
Eric Lawrence
Telerik team
answered on 18 Nov 2015, 10:55 PM
Sorry about the typos, glad you got it working.

In the Fiddler Script Editor, the View > Class Explorer command is a great way to learn about the object model available to you. The Fiddler Book is another good reference.

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
Tags
Fiddler Classic
Asked by
Zsolt
Top achievements
Rank 1
Answers by
Zsolt
Top achievements
Rank 1
Eric Lawrence
Telerik team
Share this question
or