我是這裏的新成員,所以如果我沒有列出任何需要您授予我回答的問題。Telnet vbs into Java
我的問題是,我做了一段時間的基礎類型所有telnet信息,需要通過telnet配置telewell調制解調器。
我想要做的是將其轉換成java並製作一個很好的框架,詢問什麼IP地址分配給調制解調器,而不使用vbs使用的笨重方法。 vbs停止在一個點上,並提供一個窗口,表明您應該在telnet命令窗口中寫入「xxx.xxx.xxx.xxx」代表您想要分配給調制解調器的IP地址,然後在它再次執行時斷開並嘗試再次連接。
在sub.pause彈出一個窗口後,它不幸在瑞典語中出現,但它轉換爲「在遠程登錄命令窗口中寫入所需的IP地址而不是xxx.xxx.xxx.xxx」。
希望有人爲可以給我一些還挺方向走,我就可以開始取得進展我的技能在Java :)
溴。 Shmooss
set cloner=createobject("WScript.shell")
cloner.run"cmd"
WScript.Sleep 500
cloner.SendKeys"telnet 192.168.0.254"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"admin"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"admin"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set 4WireEnable false"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set 4WMode CO"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set 4WType Annex_B"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set 4WAutoStart true"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set 4WConnected true"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set BitRateMod Fixed"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set FixedBitRate 2056kbps"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set Mode CO"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set FramerType Level2"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set Whip Inactive"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set ActivateLine true"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"port s1 set 4WActivateLine true"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"rfc1483 set transport wanlink vci 32"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"rfc1483 set transport wanlink vpi 0"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"ip set interface iplan ipaddress xxx.xxx.xxx.xxx"
Pause
Sub Pause()
WScript.Echo ("Ersätt xxx.xxx.xxx.xxx med den IP-ADRESS du vill att modemet skall ha. SEDAN TRYCK OK! OBS. Om du är osäker fråga någon vettigare :)")
End Sub
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.run"cmd"
WScript.Sleep 500
cloner.SendKeys"telnet xxx.xxx.xxx.xxx"
Pause
Sub Pause()
WScript.Echo ("Ersätt xxx.xxx.xxx.xxx med den IP-ADRESS du vill att modemet skall ha. SEDAN TRYCK OK! OBS. Om du är osäker fråga någon vettigare :)")
End Sub
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"admin"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"admin"
cloner.SendKeys("{Enter}")
WScript.Sleep 500
cloner.SendKeys"system config save"
cloner.SendKeys("{Enter}")
Wscript.Sleep 500
這是我迄今所做
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import javax.xml.ws.handler.MessageContext;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.management.ImmutableDescriptor;
import javax.swing.DropMode;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.awt.event.ActionEvent;
import javax.swing.JTextPane;
public class Window extends JFrame {
private JPanel contentPane;
private JTextField txtNewadress;
private JTextField textFieldwriteip;
private JButton btnApply;
private JTextField textProgress;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Window frame = new Window();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Window() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 400, 148);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
txtNewadress = new JTextField();
txtNewadress.setFont(new Font("Tahoma", Font.BOLD, 11));
txtNewadress.setEditable(false);
txtNewadress.setText("IP-Adress for your modem, write below");
contentPane.add(txtNewadress, BorderLayout.NORTH);
txtNewadress.setColumns(10);
textFieldwriteip = new JTextField();
textFieldwriteip.setFont(new Font("Tahoma", Font.PLAIN, 20));
contentPane.add(textFieldwriteip, BorderLayout.CENTER);
textFieldwriteip.setColumns(10);
btnApply = new JButton("SET/APPLY");
btnApply.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
connect (textFieldwriteip.getText());
}
});
contentPane.add(btnApply, BorderLayout.EAST);
textProgress = new JTextField();
textProgress.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
contentPane.add(textProgress, BorderLayout.SOUTH);
textProgress.setColumns(10);
}
void connect (String ip)
{
Socket sock = null;
PrintWriter pw = null;
try
{
sock = new Socket(ip = "192.168.0.254", 23);
pw = new PrintWriter(sock.getOutputStream());
System.out.println("Sending username");
pw.println("admin");
System.out.println("Sending password");
pw.println("admin");
System.out.println("Sending Configuration 1/15");
pw.println("port s1 set 4WireEnable false");
System.out.println("Sending Configuration 2/15");
pw.println("port s1 set 4WMode CO");
System.out.println("Sending Configuration 3/15");
pw.println("port s1 set 4WType Annex_B");
System.out.println("Sending Configuration 4/15");
pw.println("port s1 set 4WautoStart true");
System.out.println("Sending Configuration 5/15");
pw.println("port s1 set 4WConnected true");
System.out.println("Sending Configuration 6/15");
pw.println("port s1 set BitRateMod Fixed");
System.out.println("Sending Configuration 7/15");
pw.println("port s1 set FixedBitRate 2056kbps");
System.out.println("Sending Configuration 8/15");
pw.println("port s1 set Mode CO");
System.out.println("Sending Configuration 9/15");
pw.println("port s1 set FramerType Leve12");
System.out.println("Sending Configuration 10/15");
pw.println("port s1 set Whip Inactive");
System.out.println("Sending Configuration 11/15");
pw.println("port s1 set ActivateLine true");
System.out.println("Sending Configuration 12/15");
pw.println("port s1 set 4WActivateLine true");
System.out.println("Sending Configuration 13/15");
pw.println("rfc1483 set transport wanlink vci 32");
System.out.println("Sending Configuration 14/15");
pw.println("rfc1483 set transport wanlink vpi 0");
pw.close();
sock.close();
Thread.sleep(1000);
} catch (IOException | InterruptedException e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(this, "SPERMABÖG");
}
}
}