write a linux script that gathers a bunch of the important network settings in o
ID: 3764714 • Letter: W
Question
write a linux script that gathers a bunch of the important network settings in one place. the network information is scattered across a rather large number of commands and files, and it would be very convenient to have a script that outputs all of the important information together. Write a scripted named get_network_info.sh that will report the following:
whether or not the IPv4 address is a dynamic address or static address.
current IPv4 address,
MAC address, gateway router,
DNS servers, DNS domain,
NIC speed, and
NIC duplex.
To do all of this, you will need to use our standard tools like grep, sed, and awk to only list the specific details we want. The script should assume that you are gathering the information for the enp0s3 NIC.
Here is a sample run:
[user@user lab0]$ sudo ./get_network_info.sh
dynamic IPv4 address: 10.0.2.15
MAC address: 08:00:27:81:35:9f
Gateway router: 10.0.2.2
DNS server: 10.0.8.12
DNS server: 10.0.8.11
DNS domain: campus.bridgew.edu
DNS domain: comp320
NIC speed: 1000Mb/s
NIC duplex: Full
[user@user lab0]$
You should figure out how to get each individual piece of information on the command line directly before putting anything in your script.
Explanation / Answer
Option Explicit On Error Resume Next Dim objWMIService Dim objNetAdapter Dim strComputer Dim arrIPAddress Dim arrSubnetMask Dim arrGateway Dim colNetAdapters Dim errEnableStatic Dim errGateways strComputer = "." arrIPAddress = Array("192.168.1.106") arrSubnetMask = Array("255.255.255.0") arrGateway = Array("192.168.1.1") Set objWMIService = GetObject("winmgmts:\" & strComputer & " ootcimv2") Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") For Each objNetAdapter in colNetAdapters errEnableStatic = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask) If Not errEnableStatic = 0 Then WScript.Echo "Failure assigning IP/Subnet." End If errGateways = objNetAdapter.SetGateways(arrGateway) If Not errGateways = 0 Then WScript.Echo "Failure assigning Gateway." End If Next WScript.Quit
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.