1 2 import com.jcraft.jsch.*; 3 import java.awt.*; 4 import javax.swing.*; 5 6 public class ViaSOCKS5{ 7 public static void main(String [] arg){ 8 9 String proxy_host; 10 int proxy_port; 11 12 try{ 13 JSch jsch=new JSch(); 14 15 String host=JOptionPane.showInputDialog("Enter username@hostname", 16 System.getProperty("user.name")+ 17 "@localhost"); 18 String user=host.substring(0, host.indexOf('@')); 19 host=host.substring(host.indexOf('@')+1); 20 21 Session session=jsch.getSession(user, host, 22); 22 23 String proxy=JOptionPane.showInputDialog("Enter proxy server", 24 "hostname:port"); 25 proxy_host=proxy.substring(0, proxy.indexOf(':')); 26 proxy_port=Integer.parseInt(proxy.substring(proxy.indexOf(':')+1)); 27 28 session.setProxy(new ProxySOCKS5(proxy_host, proxy_port)); 29 30 UserInfo ui=new MyUserInfo(); 32 session.setUserInfo(ui); 33 34 39 session.connect(); 40 41 Channel channel=session.openChannel("shell"); 42 43 channel.setInputStream(System.in); 44 channel.setOutputStream(System.out); 45 46 channel.connect(); 47 } 48 catch(Exception e){ 49 System.out.println(e); 50 } 51 } 52 53 public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{ 54 public String getPassword(){ return passwd; } 55 public boolean promptYesNo(String str){ 56 Object [] options={ "yes", "no" }; 57 int foo=JOptionPane.showOptionDialog(null, 58 str, 59 "Warning", 60 JOptionPane.DEFAULT_OPTION, 61 JOptionPane.WARNING_MESSAGE, 62 null, options, options[0]); 63 return foo==0; 64 } 65 66 String passwd; 67 JTextField passwordField=(JTextField)new JPasswordField(20); 68 69 public String getPassphrase(){ return null; } 70 public boolean promptPassphrase(String message){ return true; } 71 public boolean promptPassword(String message){ 72 Object [] ob={passwordField}; 73 int result= 74 JOptionPane.showConfirmDialog(null, ob, message, 75 JOptionPane.OK_CANCEL_OPTION); 76 if(result==JOptionPane.OK_OPTION){ 77 passwd=passwordField.getText(); 78 return true; 79 } 80 else{ return false; } 81 } 82 public void showMessage(String message){ 83 JOptionPane.showMessageDialog(null, message); 84 } 85 final GridBagConstraints gbc = 86 new GridBagConstraints(0,0,1,1,1,1, 87 GridBagConstraints.NORTHWEST, 88 GridBagConstraints.NONE, 89 new Insets(0,0,0,0),0,0); 90 private Container panel; 91 public String [] promptKeyboardInteractive(String destination, 92 String name, 93 String instruction, 94 String [] prompt, 95 boolean[] echo){ 96 panel = new JPanel(); 97 panel.setLayout(new GridBagLayout()); 98 99 gbc.weightx = 1.0; 100 gbc.gridwidth = GridBagConstraints.REMAINDER; 101 gbc.gridx = 0; 102 panel.add(new JLabel(instruction), gbc); 103 gbc.gridy++; 104 105 gbc.gridwidth = GridBagConstraints.RELATIVE; 106 107 JTextField[] texts=new JTextField[prompt.length]; 108 for(int i=0; i<prompt.length; i++){ 109 gbc.fill = GridBagConstraints.NONE; 110 gbc.gridx = 0; 111 gbc.weightx = 1; 112 panel.add(new JLabel(prompt[i]),gbc); 113 114 gbc.gridx = 1; 115 gbc.fill = GridBagConstraints.HORIZONTAL; 116 gbc.weighty = 1; 117 if(echo[i]){ 118 texts[i]=new JTextField(20); 119 } 120 else{ 121 texts[i]=new JPasswordField(20); 122 } 123 panel.add(texts[i], gbc); 124 gbc.gridy++; 125 } 126 127 if(JOptionPane.showConfirmDialog(null, panel, 128 destination+": "+name, 129 JOptionPane.OK_CANCEL_OPTION, 130 JOptionPane.QUESTION_MESSAGE) 131 ==JOptionPane.OK_OPTION){ 132 String [] response=new String [prompt.length]; 133 for(int i=0; i<prompt.length; i++){ 134 response[i]=texts[i].getText(); 135 } 136 return response; 137 } 138 else{ 139 return null; } 141 } 142 } 143 } 144 145 146 | Popular Tags |