Java??????????
???????????? ???????[ 2017/3/10 11:19:48 ] ??????????????????? Java ??????????
?????????????????????????????????????
????1.HTTP????
????2.Socks????
????3.??????????????
????4.?????????????????????HTTP??Socks????????????
??????ο?QQ?????????????????????qq????????????????
???????????????????д????????????????????
???????????????????????????????????????????????????y????????????
???????????л?????WindowsXP??Windows7??Windows8????
????????????Java7??Swing??CXF??
???????
????1.??ν???????????????
????/**
????* ???????Bean
????*
????* @author tang
????*/
????public class NetworkBean implements Serializable {
????private static final long serialVersionUID = 1L;
????// private static sun.misc.BASE64Encoder base64Encoder = new sun.misc.BASE64Encoder();
????private Proxy.Type type;// ????????
????private String address;// ip ???
????private String port;// ????
????private String username;// ??????????????
????private String password;// ????????????????
????private String domain;// ??
????private String typeText;// ????????????????
????public NetworkBean() {
????}
????public NetworkBean(Type type?? String address?? String port?? String username?? String password) {
????this.type = type;
????this.address = address;
????this.port = port;
????this.username = username;
????this.password = password;
????}
????public NetworkBean(Type type?? String address?? String port?? String username?? String password?? String domain) {
????super();
????this.type = type;
????this.address = address;
????this.port = port;
????this.username = username;
????this.password = password;
????this.domain = domain;
????}
????public Proxy.Type getType() {
????return type;
????}
????public void setType(Proxy.Type type) {
????this.type = type;
????}
????public String getAddress() {
????return address;
????}
????public void setAddress(String address) {
????this.address = address;
????}
????public String getPort() {
????return port;
????}
????public void setPort(String port) {
????this.port = port;
????}
????public String getUsername() {
????return username;
????}
????public void setUsername(String username) {
????this.username = username;
????}
????public String getPassword() {
????return password;
????}
????public void setPassword(String password) {
????this.password = password;
????}
????public String getDomain() {
????return domain;
????}
????public void setDomain(String domain) {
????this.domain = domain;
????}
????public String getTypeText() {
????return typeText;
????}
????public void setTypeText(String typeText) {
????this.typeText = typeText;
????}
????/**
????* return domain + "" + username
????*/
????public String getDomainAndUsername() {
????return (Utils.toString(domain).trim().isEmpty()) ? username : domain.trim() + "\" + username;
????}
????/**
????* return domain + "" + username + ":" + password
????*/
????public String getDomainAndUsernameAndPassword() {
????return getDomainAndUsername() + ":" + password;
????}
????/**
????* return username + ":" + password
????*/
????public String getUsernameAndPassword() {
????return username + ":" + password;
????}
????/**
????* return (domain + "" + username + ":" + password) to 64 bit
????*/
????public String getDomainAndUsernameAndPassword64() {
????return org.apache.commons.codec.binary.Base64.encodeBase64String(getDomainAndUsernameAndPassword().getBytes());
????}
????@Override
????public String toString() {
????return "NetworkBean [type=" + type + "?? typeText=" + typeText + "?? address=" + address + "?? port=" + port + "?? username=" + username + "?? password="
????+ password + "?? domain=" + domain + "]";
????}
????}
????/**
????* ????????????????????????????????
????*
????* @param networkBean
????*/
????public static void setNetworkProxyBySystem(NetworkBean networkBean) {
????System.out.println("System Set Proxy : " + networkBean);
????if (isUserProxy(networkBean)) {
????if (networkBean.getType() == Proxy.Type.SOCKS) {
????System.getProperties().remove("http.proxyHost");
????System.getProperties().remove("http.proxyPort");
????System.getProperties().setProperty("socksProxyHost"?? networkBean.getAddress());
????System.getProperties().setProperty("socksProxyPort"?? networkBean.getPort());
????} else {
????System.getProperties().setProperty("http.proxyHost"?? networkBean.getAddress());
????System.getProperties().setProperty("http.proxyPort"?? networkBean.getPort());
????}
????Authenticator.setDefault(new BairuiAuthenticator(networkBean.getDomainAndUsername()?? networkBean.getPassword()));
????} else if (networkBean != null) {
????System.getProperties().remove("proxySet");
????System.getProperties().remove("socksProxySet");
????System.getProperties().remove("http.proxyHost");
????System.getProperties().remove("http.proxyPort");
????System.getProperties().remove("socksProxyHost");
????System.getProperties().remove("socksProxyPort");
????}
????}
????/**
????* ?????????????У??????
????*/
????public static class BairuiAuthenticator extends Authenticator {
????private String username?? password;
????public BairuiAuthenticator(String username?? String password) {
????this.username = username;
????this.password = password;
????}
????protected PasswordAuthentication getPasswordAuthentication() {
????return new PasswordAuthentication(username?? password == null ? null : password.toCharArray());
????}
????}
????2.?????CXF??Service???????????
????/**
????* ?WebService?????????????????httpClientPolicy.setAllowChunking(false);
????*
????* @param client
????*/
????public static void setWebServiceSupportProxy(Client client) {
????HTTPConduit conduit = (HTTPConduit) client.getConduit();
????HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
????httpClientPolicy.setAllowChunking(false);
????conduit.setClient(httpClientPolicy);
????}
????3.?????????????
????/**
????* ??????????????????????????
????*
????* @return ?÷?????????null???????????
????*/
????public static NetworkBean getBrowserProxy() {
????NetworkBean networkBean = new NetworkBean();
????networkBean.setTypeText(typeTexts[3]);
????networkBean.setType(Proxy.Type.DIRECT);
????String key = "reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"";// ?????????????key
????try {
????Process exec = Runtime.getRuntime().exec(key);
????try (InputStreamReader i = new InputStreamReader(exec.getInputStream()); BufferedReader ir = new BufferedReader(i)) {
????for (String line = ir.readLine(); line != null; line = ir.readLine()) {
????if (line.indexOf("ProxyServer") >= 0) {
????String[] split1 = line.split(" ");
????if (split1.length > 3) {
????String[] split2 = split1[3].trim().split(":");
????if (split2.length > 1) {
????if (!Utils.toString(split2[0]).isEmpty() && !Utils.toString(split2[1]).isEmpty()) {
????networkBean.setAddress(split2[0]);
????networkBean.setPort(split2[1]);
????networkBean.setType(Proxy.Type.HTTP);
????break;
????}
????}
????}
????}
????}
????} catch (Exception e) {
????e.printStackTrace();
????}
????} catch (Exception e) {// ???????????
????e.printStackTrace();
????}
????return networkBean;
????}
????4.?????????????
????????????????????????????????????????????????????????????????
??????????????????????????????????????
????/**
????* ?????????????????????????????????????
????*
????* @throws Exception
????*/
????private static void testNetworkProxy() throws Exception {
????testWebService();
????testURLConnection();
????}
????/**
????* ????CXF Service???50367???
????*
????* @param networkBean
????* @throws Exception
????*/
????public static void testWebService() throws Exception {
????JcptLoginService service = WebServiceUtils.getService(JcptLoginService.class?? GeneralWebServiceAddress.LOGIN_SERVICE_URL_ADD);
????String result = service.getLoginPicture();
????System.out.println(result);
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11