`

internal network proxy checking

阅读更多

internal network which is using pac url such as: http://proxypac.*.com/proxy.pac for proxying, might causing IDE(s) eg(Eclipse/Intellij) can't connect or install plugins, we can using the following code to generate the actual proxied url, and once get it then set it in IDE.

 

if you using dart sdk cmd mod, you can use 

写道
set https_proxy=username:%password%@proxy.*.com:8080

 

 

this tool code needs proxy-vole-20131209.jar

 

import com.btr.proxy.search.ProxySearch;
import com.btr.proxy.util.Logger;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.ProxySelector;
import java.net.URL;
import java.text.MessageFormat;

public class ProxyChecker extends JFrame {
    private static final long serialVersionUID = 1L;
    private JComboBox modes;
    private JButton testButton;
    private JTextField urlField;
    private JTextArea logArea;

    public ProxyChecker() {
        this.init();
    }

    private void init() {
        this.setTitle("Proxy Vole Tester");
        this.setDefaultCloseOperation(3);
        JPanel p = new JPanel();
        p.add(new JLabel("Mode:"));
        this.modes = new JComboBox(ProxySearch.Strategy.values());
        p.add(this.modes);
        p.add(new JLabel("URL:"));
        this.urlField = new JTextField(30);
        this.urlField.setText("https://pub.dartlang.org");
        p.add(this.urlField);
        this.testButton = new JButton("Check");
        this.testButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                ProxyChecker.this.testUrl();
            }
        });
        p.add(this.testButton);
        this.logArea = new JTextArea(5, 50);
        JPanel contenPane = new JPanel(new BorderLayout());
        contenPane.add(p, "North");
        contenPane.add(new JScrollPane(this.logArea), "Center");
        this.setContentPane(contenPane);
        this.pack();
        this.setLocationRelativeTo((Component) null);
        this.installLogger();
    }

    private void installLogger() {
        Logger.setBackend(new Logger.LogBackEnd() {
            public void log(Class<?> clazz, Logger.LogLevel loglevel, String msg, Object... params) {
                ProxyChecker.this.logArea.append(loglevel + "\t" + MessageFormat.format(msg, params) + "\n");
            }

            public boolean isLogginEnabled(Logger.LogLevel logLevel) {
                return true;
            }
        });
    }

    protected void testUrl() {
        try {
            if (this.urlField.getText().trim().length() == 0) {
                JOptionPane.showMessageDialog(this, "Please enter an URL first.");
                return;
            }

            this.logArea.setText("");
            ProxySearch.Strategy e = (ProxySearch.Strategy) this.modes.getSelectedItem();
            ProxySearch ps = new ProxySearch();
            ps.addStrategy(e);
            ProxySelector psel = ps.getProxySelector();
            if (psel == null) {
                JOptionPane.showMessageDialog(this, "No proxy settings available for this mode.");
                return;
            }

            ProxySelector.setDefault(psel);
            URL url = new URL(this.urlField.getText().trim());
            java.util.List result = psel.select(url.toURI());
            if (result == null || result.size() == 0) {
                JOptionPane.showMessageDialog(this, "No proxy found for this url.");
                return;
            }

            System.out.println("there are " + result.size() + " results.");
            //santiago
            //JOptionPane.showMessageDialog(this, "Proxy Settings found using " + e + " strategy.\n" + "Proxy used for URL is: " + result.get(0));
            ProxyChecker.this.logArea.append("result:" + "\t" + "Proxy used for URL is: " + result.get(0) + "\n");

        } catch (Exception var6) {
            JOptionPane.showMessageDialog(this, "Error:" + var6.getMessage(), "Error checking URL.", 0);
        }

    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ProxyChecker.setLookAndFeel();
                ProxyChecker mainFrame = new ProxyChecker();
                mainFrame.setVisible(true);
            }
        });
    }

    private static void setLookAndFeel() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception var1) {
            ;
        }

    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics