1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
/**
*
* @author jaafar
*/
import java.io.*;
import java.net.*;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.lang.management.ManagementFactory;
public class ClientFini {
public ClientFini() {}
public static void main(String args[]) {
//Déclaration des variables
int compteur=5;
int sport=3078;
final String adress="192.168.1.2";
String dateheur;
String repertoirecourante;
String dossierutilisateur;
String systèmedexploitation;
String versionsystème;
String archsystème;
long EspacedisqueTotal;
long EspacedisqueUtiliser;
long EspacedisqueLibre;
long totalMemory;
long freeMemory;
String repertoire="";
String programmes="";
Socket socket = null;
int nbrprocessor;
while(true)
try{
//**************************** création d'un socket client ****************************************
System.out.println("Le client est en cours");
socket = new Socket(adress, sport);
BufferedReader plec = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter pred = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
//********************** LES méthode de récupération des données local *****************************
dateheur=Calendar.getInstance().getTime().toLocaleString();
systèmedexploitation =System.getProperty("os.name");
dossierutilisateur=System.getProperty("user.home").replace("\\","/");
versionsystème=System.getProperty("os.version");
archsystème= System.getProperty("os.arch");
repertoire=System.getProperty("user.dir").replace("\\","/");
//******accés au disque dur c: puis récupération des information du disque.******
File file = new File( "C:");
EspacedisqueTotal = file.getTotalSpace()/1024/1024/1024;
EspacedisqueLibre = file.getFreeSpace()/1024/1024/1024;
EspacedisqueUtiliser =(EspacedisqueTotal- EspacedisqueLibre);
//************//
com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
totalMemory =mxbean.getTotalPhysicalMemorySize();
freeMemory = mxbean.getFreePhysicalMemorySize();
nbrprocessor=mxbean.getAvailableProcessors();
//******liste des programmes installés sur l'ordinateur.******
File file1 = new File( "C:\\Program Files" );
File[] files = file1.listFiles();
for ( int fileInList = 0 ; fileInList < files.length; fileInList++)
programmes+=files[fileInList].getName()+"/";
//**************************** adress mac***************************
//******************************************************************
String am="";
NetworkInterface ni = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
if (ni != null) {
byte[] mac = ni.getHardwareAddress();
if (mac != null)
{
//************************format d'affichage de l'adresse mac*****************************
try{
for (int i = 0; i < mac.length-1; i++)
am+=String.format("%02X",mac[i])+"-";
am+=String.format("%02X",mac[mac.length-1]);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
else
System.out.println("Address doesn't exist or is not accessible.");
}
else
System.out.println("Network Interface for the specified address is not found.");
//**************************** ******************************
/*format d'envoie des résultats du socket client vers le serveur */
pred.println(dateheur+"_"+am+"_"+systèmedexploitation+"_"+versionsystème+"_"+archsystème+"_"+nbrprocessor+"_"+repertoire+"_"+dossierutilisateur+"_"+EspacedisqueTotal+"_"+EspacedisqueUtiliser+"_"+EspacedisqueLibre+"_"+totalMemory+"_"+freeMemory+"_"+programmes);
plec.readLine();
socket.close();
//-------------------------------------------- scan port ------------------------------------------
new Thread(){
public void run()
{
int pport=3016;//initialisation du numéro de port
int port=3009;
String hostname = null;
PrintWriter pred=null;
Socket socket=null;
for (port = 70; port <100; port++)
try {
socket = new Socket(adress, pport);
pred = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
InetAddress remote = InetAddress.getLocalHost();
hostname = remote.getHostName();
Socket s = new Socket(remote, port);
pred.println("Le port " + port +"de la machine " +hostname+" est ouvert");
s.close();
}
catch (IOException ex) {
try
{
pred.println(" Le port " + port + " de la machine " + hostname+" est fermé");
}catch(Exception f){
}
}
try {
pred.println("con"); //*****message d'arrêt du socket du scan des ports*****
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
//----------------------------------------------------------
//Fermeture de socket
socket.close();
}
catch(IOException e){
try
{
socket.close();
}catch(Exception e1)
{
}
try {
compteur--;
if (compteur==0)
{
compteur=5;
Thread.currentThread().sleep(10000);
}
else
Thread.currentThread().sleep(4000);//***le client réessaie de se connecter chaque 4s tant que le serveur n'est pas connecté.
System.out.println("...Loading");
} catch (InterruptedException e2) {
}
}
}} |
Partager