@@ -180,3 +180,51 @@ def mac(debug=False):
180180 if debug :
181181 print (str (e ))
182182 return GENERAL_ERROR_MESSAGE
183+
184+ def network_control (command , device = "eth0" , debug = False ):
185+ """
186+ Control network adaptor.
187+
188+ :param command: input command
189+ :type command: str
190+ :param device: network device name
191+ :type device:str
192+ :param debug: flag for using debug mode
193+ :type debug:bool
194+ :return: True in successful
195+ """
196+ try :
197+ cmd = "up"
198+ if command == "down" :
199+ cmd = "down"
200+ sub .Popen (["ifconfig" , device , cmd ],
201+ stderr = sub .PIPE , stdin = sub .PIPE , stdout = sub .PIPE )
202+ return True
203+ except Exception as e :
204+ if debug :
205+ print (str (e ))
206+ return GENERAL_ERROR_MESSAGE
207+
208+ def network_enable (device = "eth0" , debug = False ):
209+ """
210+ Shortcut to enable network adaptor.
211+
212+ :param device: network device name
213+ :type device:str
214+ :param debug: flag for using debug mode
215+ :type debug:bool
216+ :return: True in successful
217+ """
218+ return network_control ("up" ,device = device ,debug = debug )
219+
220+ def netowrk_disable (device = "eth0" , debug = False ):
221+ """
222+ Shortcut to disable network adaptor.
223+
224+ :param device: network device name
225+ :type device:str
226+ :param debug: flag for using debug mode
227+ :type debug:bool
228+ :return: True in successful
229+ """
230+ return network_control ("down" , device = device , debug = debug )
0 commit comments