WEB端UI自动化测试(六)浏览器代理设置

一、获取本地IP地址

Linux系统和windows系统的获取方法不同,这里已Windows系统举例说明,JDK封装了getHostAddress()方法来获得IP地址

1.获得本机所有的网络接口

Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();

 

2.获得网络接口对应的IP

public static void IPcon() throws SocketException {
        //getNetworkInterfaces()获得网络接口
        Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
        while (nifs.hasMoreElements()) {
            NetworkInterface nif = nifs.nextElement();
            Enumeration<InetAddress> addresses = nif.getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress addr = addresses.nextElement();
                if ((!addr.isLinkLocalAddress()) && (!addr.isLoopbackAddress()) && ((addr instanceof Inet4Address))) {// 只看IPV4
                    System.out.println("网络接口地址:"+nif.getName());
                    System.out.println("IP地址:"+addr.getHostAddress());
                }

            }

        }
    }

二、修改注册表

 cmd下运行Regedit,打开注册表,查看Internet Settings下的属性

设置代理

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d \"0x1\" /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d IP:port /f

三、还原代理

先将代理服务器的√去掉

通过reg add 命令修改ProxyEnable的值,/v 代表值  /t代表格式  /d 代表数值 ,0x1代表打勾,0x0代表没打勾  /f 代表强制执行
reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v ProxyEnable /t REG_DWORD /d \"0x0\" /f
 
posted @ 2019-10-17 19:48  归藏  阅读(585)  评论(0)    收藏  举报