c#如何在不使用本地代理服务器的情况下从客户端跟踪所有web活动和web URL



(用c#编程)嗨,我想跟踪和记录所有在任何浏览器上启动的网络活动和网络URL。我知道我们可以在使用本地代理服务器和路由的情况下做到这一点,但我想知道,如果没有本地代理服务器而没有路由,我们如何做到这一步。

我真正想开发的是:-C#wpf应用程序跟踪所有的网络活动,并将所有数据(URL名称+时间+持续时间)转储到数据库中。

class浏览位置{公共结构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;

    }
}

类程序

{
    static void Main(string[] args)
    {
        Console.WriteLine("Internet Explorer: ");
        (new List<browserlocation.URLDetails>(browserlocation.InternetExplorer())).ForEach(u =>
        {
            Console.WriteLine("[{0}]rn{1}rn", 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();
        } 
    }
}

最新更新