c# 如何在不使用本地代理服务器的情况下跟踪来自客户端的所有 Web 事件和 Web URL?

标签 c# browser window monitoring

(在 C# 中以编程方式) 您好,我想跟踪并记录在任何浏览器上触发的所有网络事件和网络 URL。 我知道我们可以在使用本地代理服务器和路由时做到这一点,但我想知道如果没有本地代理服务器而没有路由,我们怎么能做到这一点。

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

最佳答案

类浏览器位置 { 公共(public)结构 URL 详细信息 {

        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)计划

{

    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();
        } 
    }
}

关于c# 如何在不使用本地代理服务器的情况下跟踪来自客户端的所有 Web 事件和 Web URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36492701/

相关文章:

c# - 使用适用于 .NET 的 AWS S3 SDK 从 Amazon S3 下载并行批处理文件

c# - 通过 OleDb (C#) 将 Access 2010 记录锁定设置为乐观锁定

c# - 如何使用 .NET CLI 指定对其他项目的依赖关系?

qt - 如何使用QT5创建类似VS2013的无框窗口样式

macos - OS X 在应用程序打开、退出和更改焦点时发出通知

c# - GetExpressCheckoutDetails 在 asp.net 中返回 session 过期(10411 错误)(仅在某些计算机上)

JavaScript 在页面上运行,但最后删除了自己的 DOM 节点。我如何测试它做了什么?

html - 为什么谷歌浏览器在元素放置方面不够精确?

javascript - 加载新的 html 页面时,JS 变量是否会被销毁?

c# - 分割WPF窗口