📄 proxyutil.java
字号:
} catch (Throwable t) {
throw new IOException("Failed to get proxy information from Firefox profiles: " + t.getMessage());
}
}
public static BrowserProxySettings lookupIEProxySettings() throws IOException {
try {
Vector addresses = new Vector();
Vector proxies = new Vector();
String proxyServerValue = null;
String proxyOveride = null;
if (ApplicationLauncher.checkVersion("1.3") && System.getProperty("os.name") != null
&& System.getProperty("os.name").startsWith("Windows")) {
/**
* We can use jRegistryKey API to lookup IE settings in the
* registry
*/
RegistryKey key = new RegistryKey(RootKey.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
if (key != null && key.hasValue("ProxyEnable")) {
/**
* We have ProxyEnable so check to see if we are using a
* proxy
*/
if (key.getValue("ProxyEnable").getStringValue().equals("1")) {
if (key.hasValue("ProxyServer")) {
/**
* We have some proxy settings. The values will be
* in the format "server.proxy.net:8888" or
*/
proxyServerValue = key.getValue("ProxyServer").getStringValue();
if (key.hasValue("ProxyOverride")) {
/**
* There is a list of local address which do not
* require a proxy. The values will be in the
* format "localhost;3sp.co.uk;shabby.net"
*/
proxyOveride = key.getValue("ProxyOverride").getStringValue();
}
}
} else {
}
}
} else {
if (System.getProperty("java.vendor").startsWith("Microsoft")) {
try {
Class clazz = Class.forName("com.ms.lang.RegKey");
int userRoot = clazz.getField("USER_ROOT").getInt(null);
int keyOpenAll = clazz.getField("KEYOPEN_ALL").getInt(null);
/* DEBUG */log.info("Looking for root registry key");
Object rootKey = clazz.getMethod("getRootKey", new Class[] { int.class })
.invoke(null, new Object[] { new Integer(userRoot) });
/* DEBUG */log.info("Get IE registry key");
Object key = clazz
.getConstructor(new Class[] { clazz, String.class, int.class })
.newInstance(
new Object[] {
rootKey,
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
new Integer(keyOpenAll) });
/* DEBUG */log.info("Checking if proxy enabled");
if (((Integer) (clazz.getMethod("getIntValue", new Class[] { String.class })
.invoke(key, new Object[] { "ProxyEnable" }))).intValue() == 1) {
/* DEBUG */log.info("Getting proxy server list");
proxyServerValue = (String) (clazz.getMethod("getStringValue",
new Class[] { String.class, String.class })
.invoke(key, new Object[] { "ProxyServer", "" }));
/* DEBUG */log.info("Getting proxy overides");
proxyOveride = (String) (clazz.getMethod("getStringValue", new Class[] { String.class, String.class })
.invoke(key, new Object[] { "ProxyOverride", "" }));
}
} catch (Throwable t) {
t.printStackTrace();
}
/**
* We can lookup settings using Microsoft classes.
*/
//#ifdef MSJAVA
/*
com.ms.lang.RegKey key = new com.ms.lang.RegKey(com.ms.lang.RegKey.getRootKey(com.ms.lang.RegKey.USER_ROOT),
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
com.ms.lang.RegKey.KEYOPEN_ALL);
if (key.getIntValue("ProxyEnable") == 1) {
proxyServerValue = key.getStringValue("ProxyServer");
proxyOveride = key.getStringValue("ProxyOverride");
}
*/
//#endif
} else {
/* DEBUG */log.info("Could not read registry setting, unsupported java runtime "
/* DEBUG */+ System.getProperty("java.version")
/* DEBUG */+ " "
/* DEBUG */+ System.getProperty("java.vendor"));
}
}
ProxyInfo p;
if (proxyServerValue != null && proxyServerValue.indexOf(';') > -1) {
/**
* Format is multiple
* "ftp=ftp.com:4444;gopher=gopher.com:3333;http=198.162.1.119:8888;https=https.com:2222;socks=socks.com:1111"
*/
StringTokenizer tokens = new StringTokenizer(proxyServerValue, ";");
while (tokens.hasMoreTokens()) {
p = createProxyInfo(tokens.nextToken(), "IE Proxy Settings");
proxies.addElement(p);
}
} else if (proxyServerValue != null) {
/**
* Format is single "http=server.proxy.net:8888" or
* "server.proxy.net:8888"
*/
p = createProxyInfo(proxyServerValue, "IE Proxy Settings");
proxies.addElement(p);
}
BrowserProxySettings bps = new BrowserProxySettings();
bps.browser = "Internet Explorer";
bps.proxies = new ProxyInfo[proxies.size()];
proxies.copyInto(bps.proxies);
if (proxyOveride != null) {
StringTokenizer tokens = new StringTokenizer(proxyOveride, ";");
while (tokens.hasMoreTokens()) {
addresses.addElement(tokens.nextToken());
}
}
bps.bypassAddr = new String[addresses.size()];
addresses.copyInto(bps.bypassAddr);
return bps;
} catch (Throwable t) {
t.printStackTrace();
throw new IOException("Failed to lookup list of proxies from IE: " + t.getMessage());
}
}
private static ProxyInfo createProxyInfo(String proxyInfo, String sourceIdent) {
ProxyInfo proxy = new ProxyInfo();
int idx = proxyInfo.indexOf('=');
int idx2 = proxyInfo.indexOf(':');
proxy.protocol = idx > -1 ? proxyInfo.substring(0, idx) : "all";
proxy.hostname = proxyInfo.substring((idx > -1 ? idx + 1 : 0), idx2);
proxy.port = Integer.parseInt(proxyInfo.substring(idx2 + 1));
proxy.sourceIdent = sourceIdent;
proxy.username = "";
proxy.password = "";
return proxy;
}
public static void main(String[] args) throws Exception {
BrowserProxySettings settings = lookupFirefoxProxySettings();
/* DEBUG */log.info("Browser = " + settings.getBrowser());
ProxyInfo[] info = settings.getProxies();
for (int i = 0; i < info.length; i++) {
/* DEBUG */log.info(" " + info[i].toUri() + " [" + info[i].getSourceIdent() + "]");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -