File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import time
3
+ count = 0
4
+ string = ""
5
+ interfaces = []
6
+ for dirname , dirnames , filenames in os .walk ('/sys/class/net/' ):
7
+ for subdirname in dirnames :
8
+ if subdirname != "lo" :
9
+ #Here we are assigning an arbitrary IP which could be a different one. This is just to get the interface up
10
+ interfaces .append (subdirname )
11
+ ip = 100 + count
12
+ string += "auto " + subdirname
13
+ string += "\n iface " + subdirname + " inet static"
14
+ string += "\n address 10.0.0." + str (ip )
15
+ if count == 0 :
16
+ string += "\n gateway 10.0.0.1"
17
+ string += "\n netmask 255.255.255.0\n \n "
18
+ count = count + 1
19
+
20
+ with open ("/etc/network/interfaces" , "w" ) as text_file :
21
+ text_file .write (string )
22
+
23
+ for item in interfaces :
24
+ os .system ("sudo ifup " + item )
25
+ f = os .popen ("sudo ethtool " + item + " | grep -i \" Link detected\" " )
26
+ result = f .read ()
27
+ count = 0
28
+ while result .find ("yes" ) == - 1 :
29
+ time .sleep (5 )
30
+ f = os .popen ("sudo ethtool " + item + " | grep -i \" Link detected\" " )
31
+ result = f .read ()
32
+ count = count + 1
33
+ print result
34
+ if count > 20 :
35
+ break
You can’t perform that action at this time.
0 commit comments