我们正在使用Java编码来制作桌面应用程序但我们无法继续,因为我们无法收集有关硬盘驱动器的数据。更具体地说,我们需要收集有关硬状态的数据并将它们发送到服务器应用程序。
我们使用的代码是
public class MainFrame extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try
{
server = new ServerSocket(9999);
}
catch (Exception err)
{
System.out.println(err);
}
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
while (true)
{
Socket client = server.accept();
BufferedReader r = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter w = new PrintWriter(client.getOutputStream(), true);
String line;
String l="cnx";
String d ="dsk";
line = r.readLine();
if ( line.equals(l) ){
String msg = "";
String msgs =" Paquetsÿ: envoy‚s = 4, re‡us = 0, perdus = 4 (perte 100%),";
w.println("Veuillez attendre durant le traitement de votre demande...");
Process p = Runtime.getRuntime().exec("ping google.com");
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String readline;
while ((readline = reader.readLine()) != null) {
System.out.println(readline);
msg = readline;
}
if (msg.equals(msgs)) w.println("Connexion n'est pas établie sur ce PC");
else w.println("Connexion établie sur ce PC");
}
if ( line.equals(d) ){
String msg="";
w.println("Veuillez attendre durant le traitement de votre demande...");
Process p = Runtime.getRuntime().exec("chkdsk");
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String readline;
while ((readline = reader.readLine()) != null) {
System.out.println(msg);
msg += readline +"\n";
}
w.println(msg);
}
client.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private ServerSocket server;
});}
/**
* Create the frame.
*/
public MainFrame() {
setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\ASUS\\Desktop\\stage\\logo.jpg"));
setTitle("Agent");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(Color.BLACK);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
this.setVisible(true);
}
}
答案 0 :(得分:0)
您需要什么样的数据?您可以使用java.io.File收集一些数据,并且系统都可以在JDK下使用。否则,您可以使用Runtime.exec()来获取其他数据。
以下是获取存在的驱动器的代码::
server {
listen 80;
listen [::]:80;
server_name my.app.url;
location / {
rewrite ^ https://$host$request_uri? permanent;
}
location ^~ /.well-known {
allow all;
root /data/letsencrypt/;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name my.app.url;
ssl on;
add_header Strict-Transport-Security "max-age=31536000" always;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!ADH:!AECDH:!MD5;";
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4;
ssl_certificate /etc/letsencrypt/live/my.app.url/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/my.app.url/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/my.app.url/chain.pem;
access_log /dev/stdout;
error_log /dev/stderr info;
# other configs
}