Java - script para reiniciar adaptador ethernet

 
Vista:
Imágen de perfil de Fernando
Val: 18
Ha disminuido su posición en 2 puestos en Java (en relación al último mes)
Gráfica de Java

script para reiniciar adaptador ethernet

Publicado por Fernando (26 intervenciones) el 08/08/2015 01:17:20
Hola, no sé si será este el lenguaje indicado, pero necesito un script para deshabilitar-habilitar cada cierto tiempo el adaptador de red.

Que lenguaje es el más apropiado?

Saludos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
1
Responder

script para reiniciar adaptador ethernet

Publicado por Jack (1 intervención) el 08/08/2015 05:42:48
Hola que SO ocupas.
Mira el GNU/Linux puedes crear un script de bash
Para que te deshabilite tu adaptador de red y utilizas un cron para programar una tarea que se realice cada tiempo.
O puedes ocupar python para que ejecute el script.
1
2
3
4
5
6
7
8
#!/bin/bash
#
# Script to enable my internet
# Usage: internetgo
#
ifconfig eth0 down
ifconfig eth0 up
exit 0

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
import os
import threading
import time
import logging
def printit():
resultado = os.system("ifconfig eth0 down")
print "Ejecutando comando"
if __name__ == '__main__':
t = threading.Timer(3.0, hello)
t..setName('t1')
logging.debug('iniciando timer...')
t.start()
time.sleep(2)
Java
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
public class P15 extends Thread {
    private static Thread t;
 
    public void run() {
        if (Thread.currentThread() == t) {
             try {
    	Process process = Runtime.getRuntime().exec("ifconfig eth0 down");
    } catch (IOException e) {
    	e.printStackTrace();
    }
            System.out.println(" T1 antes del bloqueo.");
 
            synchronized (t) {
 
                System.out.println(" T1 bloqueando antes de dormir. ");
 
                doSleep(2000);
            }
 
            System.out.println(" T1 bloqueo liberado.");
 
        } else {
 
            System.out.println(" T2 antes del bloqueo. ");
 
            synchronized (t) {
                 try {
    	Process process = Runtime.getRuntime().exec("ifconfig eth0 up");
    } catch (IOException e) {
    	e.printStackTrace();
    }
                System.out.println(" T2 bloqueando antes de dormir. ");
 
                doSleep(1000);
 
            }
 
            System.out.println(" T2 bloqueo liberado. ");
        }
    }
 
    private void doSleep(long delay) {
        try {
            Thread.sleep(delay);
        } catch (InterruptedException ie) {
            ;
        }
    }
 
    public static void main(String args[]) {
        t = new P15();
        P15 t2 = new P15();
        t.setName("t1");
        t2.setName("t2");
        //t2.setPriority(MAX_PRIORITY);
        t.start();
        t2.start();
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar