Ankur Tripathi
Ankur Tripathi

Reputation: 691

c# How to track all web activity and web URL from client without using local proxy server?

(programmatically in c#) Hi, I want to track and log all web activity and web URL fired on any browser. I know we can do this while using Local proxy server and routing but I want to know that how can we do that without the Local proxy server without the routing.

What i exactly want to develop:- C# wpf Application track all web activity and dump all the data(URL name + Time + Duration) inside the database.

Upvotes: 2

Views: 5265

Answers (1)

noob
noob

Reputation: 11

class browserlocation { public struct URLDetails {

        public String URL;


        public String Title;
    }
    public static URLDetails[] InternetExplorer()
    {
        Process[] pname = Process.GetProcessesByName("iexplore");
        if (pname.Length == 0) {
            Console.Write("Process is not running ");
        }

        System.Collections.Generic.List<URLDetails> URLs = new System.Collections.Generic.List<URLDetails>();
        var shellWindows = new SHDocVw.ShellWindows();
        foreach (SHDocVw.InternetExplorer ie in shellWindows)
            URLs.Add(new URLDetails() { URL = ie.LocationURL, Title = ie.LocationName });
        return URLs.ToArray();
    }
    public static string GetChromeUrl(Process process)
    {
        if (process == null)
            throw new ArgumentNullException("process");

        if (process.MainWindowHandle == IntPtr.Zero)
            return null;

        AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle);
        if (element == null)
            return null;

        AutomationElement edit = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
        return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;


    }

}

class program

{

    static void Main(string[] args)
    {
        Console.WriteLine("Internet Explorer: ");
        (new List<browserlocation.URLDetails>(browserlocation.InternetExplorer())).ForEach(u =>
        {
            Console.WriteLine("[{0}]\r\n{1}\r\n", u.Title, u.URL);
        });

        Console.Write("\n press enter to view Chrome current tab URL");
        Console.ReadLine();

        foreach (Process process in Process.GetProcessesByName("chrome"))
        {
            string url = browserlocation.GetChromeUrl(process);
            if (url == null)
                continue;

            Console.WriteLine("CH Url for '" + process.MainWindowTitle + "' is " + url);
            Console.ReadLine();
        } 
    }
}

Upvotes: 1

Related Questions