📄 hardinfo.java
字号:
import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.lang.Runtime;import java.net.*;class hardinfo extends JFrame implements ActionListener{ Container c; JButton cpuinfo,meminfo,dma,filesystems,interrupts,partitions,ioport,Back; JLabel selectip; JTextArea txtarea; JTextField txt_ip; JScrollPane scroll; hardinfo() { c=getContentPane(); c.setLayout(null); setTitle("HardwareInformation"); setSize(new Dimension(650,650)); setLocation(60,50); setVisible(true); cpuinfo=new JButton("cpuinfo"); meminfo=new JButton("meminfo"); dma=new JButton("dma"); filesystems=new JButton("filesystems"); interrupts=new JButton("interrupts"); partitions=new JButton("partitions"); ioport=new JButton("ioport"); Back=new JButton("Back"); //ipaddress=new JButton("ipaddress"); selectip=new JLabel("Select IP"); txt_ip=new JTextField(); txtarea=new JTextArea(); scroll=new JScrollPane(txtarea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); add(cpuinfo); add(meminfo); add(dma); add(filesystems); add(interrupts); add(partitions); add(ioport); add(Back); add(selectip); // add(ipaddress); add(txt_ip); //add(txtarea); add(scroll); cpuinfo.setBounds(50,200,100,25); meminfo.setBounds(50,250,100,25); dma.setBounds(50,300,100,25); filesystems.setBounds(50,350,100,25); interrupts.setBounds(50,400,100,25); partitions.setBounds(50,450,100,25); ioport.setBounds(50,500,100,25); Back.setBounds(50,550,100,25); txt_ip.setBounds(300,200,100,30); txtarea.setBounds(300,250,450,450); scroll.setBounds(299,240,350,350); selectip.setBounds(200,200,100,20); // ipaddress.setBounds(400,200,100,60); cpuinfo.addActionListener(this); meminfo.addActionListener(this); dma.addActionListener(this); filesystems.addActionListener(this); interrupts.addActionListener(this); partitions.addActionListener(this); ioport.addActionListener(this); Back.addActionListener(this); try { String l="mkdir /root/NetworkMonitoring_mangalam/hardware"; Runtime r=Runtime.getRuntime(); Process p=null; p=r.exec(l); } catch(Exception e) { System.out.println("Error in read"+e); } } public void actionPerformed(ActionEvent e) { if(e.getSource().equals(Back)) { monitoring m=new monitoring(); this.setVisible(false); m.setVisible(true); } else if(e.getSource().equals(cpuinfo)) { String s=txt_ip.getText(); try { String l="ssh student@"+s+" cat /proc/cpuinfo"; Runtime r=Runtime.getRuntime(); Process p=r.exec(l); String s1="",s2=""; InputStream in=p.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); FileOutputStream fos= new FileOutputStream("/root/NetworkMonitoring_mangalam/hardware/cpuinfo"); PrintWriter pw=new PrintWriter(fos,true); while((s1=br.readLine())!=null) { pw.println(s1); } FileInputStream fis=new FileInputStream("/root/NetworkMonitoring_mangalam/hardware/cpuinfo"); BufferedReader b=new BufferedReader(new InputStreamReader(fis)); while((s2=b.readLine())!=null) { txtarea.append(s2+"\n"); } } catch(Exception ae) { System.out.println("Error in read"+ae); } } else if(e.getSource().equals(meminfo)) { String s=txt_ip.getText(); try { String l="ssh student@"+s+" cat /proc/meminfo"; Runtime r=Runtime.getRuntime(); Process p=null; p=r.exec(l); String s1="",s2=""; InputStream in=p.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); FileOutputStream fos= new FileOutputStream("/root/NetworkMonitoring_mangalam/hardware/meminfo"); PrintWriter pw=new PrintWriter(fos,true); while((s1=br.readLine())!=null) { pw.println(s1); } FileInputStream fis=new FileInputStream("/root/NetworkMonitoring_mangalam/hardware/meminfo"); BufferedReader b=new BufferedReader(new InputStreamReader(fis)); while((s2=b.readLine())!=null) { txtarea.append(s2+"\n"); } } catch(Exception ae) { System.out.println("Error in read"+ae); } } else if(e.getSource().equals(dma)) { String s=txt_ip.getText(); try { String l="ssh student@"+s+" cat /proc/dma"; Runtime r=Runtime.getRuntime(); Process p=null; p=r.exec(l); String s1="",s2=""; InputStream in=p.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); FileOutputStream fos= new FileOutputStream("/root/NetworkMonitoring_mangalam/hardware/dma"); PrintWriter pw=new PrintWriter(fos,true); while((s1=br.readLine())!=null) { pw.println(s1); } FileInputStream fis=new FileInputStream("/root/NetworkMonitoring_mangalam/hardware/dma"); BufferedReader b=new BufferedReader(new InputStreamReader(fis)); while((s2=b.readLine())!=null) { txtarea.append(s2+"\n"); } } catch(Exception ae) { System.out.println("Error in read"+ae); } } else if(e.getSource().equals(filesystems)) { String s=txt_ip.getText(); try { String l="ssh student@"+s+" cat /proc/filesystems"; Runtime r=Runtime.getRuntime(); Process p=null; p=r.exec(l); String s1="",s2=""; InputStream in=p.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); FileOutputStream fos= new FileOutputStream("/root/NetworkMonitoring_mangalam/hardware/filesystems"); PrintWriter pw=new PrintWriter(fos,true); while((s1=br.readLine())!=null) { pw.println(s1); } FileInputStream fis=new FileInputStream("/root/NetworkMonitoring_mangalam/hardware/filesystems"); BufferedReader b=new BufferedReader(new InputStreamReader(fis)); while((s2=b.readLine())!=null) { txtarea.append(s2+"\n"); } } catch(Exception ae) { System.out.println("Error in read"+ae); } } else if(e.getSource().equals(interrupts)) { String s=txt_ip.getText(); try { String l="ssh student@"+s+" cat /proc/interrupts"; Runtime r=Runtime.getRuntime(); Process p=null; p=r.exec(l); String s1="",s2=""; InputStream in=p.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); FileOutputStream fos= new FileOutputStream("/root/NetworkMonitoring_mangalam/hardware/interrupts"); PrintWriter pw=new PrintWriter(fos,true); while((s1=br.readLine())!=null) { pw.println(s1); } FileInputStream fis=new FileInputStream("/root/NetworkMonitoring_mangalam/hardware/interrupts"); BufferedReader b=new BufferedReader(new InputStreamReader(fis)); while((s2=b.readLine())!=null) { txtarea.append(s2+"\n"); } } catch(Exception ae) { System.out.println("Error in read"+ae); } } else if(e.getSource().equals(partitions)) { String s=txt_ip.getText(); try { String l="ssh student@"+s+" cat /proc/partitions"; Runtime r=Runtime.getRuntime(); Process p=null; p=r.exec(l); String s1="",s2=""; InputStream in=p.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); FileOutputStream fos= new FileOutputStream("/root/NetworkMonitoring_mangalam/hardware/partitions"); PrintWriter pw=new PrintWriter(fos,true); while((s1=br.readLine())!=null) { pw.println(s1); } FileInputStream fis=new FileInputStream("/root/NetworkMonitoring_mangalam/hardware/partitions"); BufferedReader b=new BufferedReader(new InputStreamReader(fis)); while((s2=b.readLine())!=null) { txtarea.append(s2+"\n"); } } catch(Exception ae) { System.out.println("Error in read"+ae); } } else if(e.getSource().equals(ioport)) { String s=txt_ip.getText(); try { String l="ssh student@"+s+" cat /proc/ioports"; Runtime r=Runtime.getRuntime(); Process p=null; p=r.exec(l); String s1="",s2=""; InputStream in=p.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); FileOutputStream fos= new FileOutputStream("/root/NetworkMonitoring_mangalam/hardware/ioports"); PrintWriter pw=new PrintWriter(fos,true); while((s1=br.readLine())!=null) { pw.println(s1); } FileInputStream fis=new FileInputStream("/root/NetworkMonitoring_mangalam/hardware/ioports"); BufferedReader b=new BufferedReader(new InputStreamReader(fis)); while((s2=b.readLine())!=null) { txtarea.append(s2+"\n"); } } catch(Exception ae) { System.out.println("Error in read"+ae); } } } public static void main(String a[]) { new hardinfo(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -