Java - Obtener procesos

 
Vista:

Obtener procesos

Publicado por Jose Miguel (8 intervenciones) el 31/10/2013 15:17:16
necesito saber los procesos de una pc en la red , osea los procesos de Windows , conosco su ip y su mac , necesito saber los procesos que esta ejecutando esa pc en la red .
por favor ayuaaaaa ...
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

obtener Mac e IP

Publicado por Jose Miguel (8 intervenciones) el 31/10/2013 19:34:59
este es el codigo de obtener la mac y e ip de la pc
usalo bien ...

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
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.text.ParseException;
import java.util.StringTokenizer;
 
public final class DireccionMac {
 
	private final static String getMacAddress() throws IOException {
		String os = System.getProperty("os.name");
		try {
			if (os.startsWith("Windows")) {
				return windowsParseMacAddress(windowsRunIpConfigCommand());
			} else if (os.startsWith("Linux")) {
				return linuxParseMacAddress(linuxRunIfConfigCommand());
			} else {
				throw new IOException("Sistema operativo desconocido: " + os);
			}
		} catch (ParseException ex) {
			ex.printStackTrace();
			throw new IOException(ex.getMessage());
		}
	}
 
	private final static String linuxParseMacAddress(String ipConfigResponse)
			throws ParseException {
		String localHost = null;
		try {
			localHost = InetAddress.getLocalHost().getHostAddress();
		} catch (java.net.UnknownHostException ex) {
			ex.printStackTrace();
			throw new ParseException(ex.getMessage(), 0);
		}
 
		StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n");
		String lastMacAddress = null;
 
		while (tokenizer.hasMoreTokens()) {
			String line = tokenizer.nextToken().trim();
			boolean containsLocalHost = line.indexOf(localHost) >= 0;
 
			if (containsLocalHost && lastMacAddress != null) {
				return lastMacAddress;
			}
 
			int macAddressPosition = line.indexOf("HWaddr");
			if (macAddressPosition <= 0)
				continue;
 
			String macAddressCandidate = line.substring(macAddressPosition + 6)
					.trim();
			if (linuxIsMacAddress(macAddressCandidate)) {
				lastMacAddress = macAddressCandidate;
				continue;
			}
		}
 
		ParseException ex = new ParseException(
				"Imposible obtener la dirección MAC " + localHost + " desde ["
						+ ipConfigResponse + "]", 0);
		ex.printStackTrace();
		throw ex;
	}
 
	private final static boolean linuxIsMacAddress(String macAddressCandidate) {
		if (macAddressCandidate.length() != 17)
			return false;
		return true;
	}
 
	private final static String linuxRunIfConfigCommand() throws IOException {
		Process p = Runtime.getRuntime().exec("ifconfig");
		InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
 
		StringBuffer buffer = new StringBuffer();
		for (;;) {
			int c = stdoutStream.read();
			if (c == -1)
				break;
			buffer.append((char) c);
		}
		String outputText = buffer.toString();
 
		stdoutStream.close();
 
		return outputText;
	}
 
	private final static String windowsParseMacAddress(String ipConfigResponse)
			throws ParseException {
		String localHost = null;
		try {
			localHost = InetAddress.getLocalHost().getHostAddress();
		} catch (java.net.UnknownHostException ex) {
			ex.printStackTrace();
			throw new ParseException(ex.getMessage(), 0);
		}
 
		StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n");
		String lastMacAddress = null;
 
		while (tokenizer.hasMoreTokens()) {
			String line = tokenizer.nextToken().trim();
 
			if (line.endsWith(localHost) && lastMacAddress != null) {
				return lastMacAddress;
			}
 
			int macAddressPosition = line.indexOf(":");
			if (macAddressPosition <= 0)
				continue;
 
			String macAddressCandidate = line.substring(macAddressPosition + 1)
					.trim();
			if (windowsIsMacAddress(macAddressCandidate)) {
				lastMacAddress = macAddressCandidate;
				continue;
			}
		}
 
		ParseException ex = new ParseException(
				"Imposible obtener dirección MAC desde [" + ipConfigResponse
						+ "]", 0);
		ex.printStackTrace();
		throw ex;
	}
 
	private final static boolean windowsIsMacAddress(String macAddressCandidate) {
		if (macAddressCandidate.length() != 17)
			return false;
 
		return true;
	}
 
	private final static String windowsRunIpConfigCommand() throws IOException {
		Process p = Runtime.getRuntime().exec("ipconfig /all");
		InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
 
		StringBuffer buffer = new StringBuffer();
		for (;;) {
			int c = stdoutStream.read();
			if (c == -1)
				break;
			buffer.append((char) c);
		}
		String outputText = buffer.toString();
 
		stdoutStream.close();
 
		return outputText;
	}
 
	public final static void main(String[] args) {
		try {
			System.out.println("Sistema Operativo     : "
					+ System.getProperty("os.name"));
			System.out.println("Dirección IP          : "
					+ InetAddress.getLocalHost().getHostAddress());
			System.out.println("Dirección Física (MAC): " + getMacAddress());
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 686
Bronce
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

obtener Mac e IP

Publicado por xve (345 intervenciones) el 01/11/2013 08:51:43
Muchas gracias Jose Miguel!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar