

It also generates help and usage messages and issues errors when the user enters any invalid arguments.
PYTHON MAC ADDRESS GENERATION FROM STRING HOW TO
The program defines the arguments it requires and argparse will figure out how to parse these arguments. The argparse module makes it convenient to write user-friendly command-line interfaces. This instruction executes the ifconfig command using Python. We are going to focus on one particular function that is used to execute the system commands. It contains several functions that can be used. The subprocess module is used to execute system commands using Python. Up until now, we manually typed the commands and executed them but we can automate the entire process using Python so that we just have to provide the script with the interface name and the new MAC Address. To check whether the MAC Address was changed to what we specified, execute the ifconfig command. sudo ifconfig enp0s3 upĪfter executing the above command, you enable the interface again so that you can access the internet. Now the MAC Address of the interface enp0s3 has been changed but to use it, we need to enable the interface again using the following command. The above command changes the existing MAC Address (08:00:27:35:21:FF) to a new MAC Address (00:11:22:33:44:55) specified in the command itself. After this, the next command to be executed will change the MAC Address. We need to take the interface down (disabling it) first if we need to change the MAC Address. What that means is you will no longer be able to connect to the internet. The above command when executed, takes the interface down. Now that we know the interface name whose MAC Address we want to change, we can move to the next command. For instance, from the above output, enp0s3 is the name of the interface and the ether field on the third line has the MAC Address ( 08:00:27:35:21:ff in our case). We can get the interface name and the existing MAC Address from the output produced by ifconfig. This information can be obtained by executing the ifconfig command. enp0s3: flags=41 inet 10.0.2.5 netmask 255.255.255.0 broadcast 10.0.2.255 ether 08:00:27:35:21:ff txqueuelen 1000 (Ethernet) RX packets 13962 bytes 17732985 (17.7 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 7969 bytes 975852 (975.8 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0įirst of all, to change the MAC Address we need to know the interface name and the existing MAC Address. The above command produces the following output.

The first step is to identify the interface whose MAC Address you want to change and you can do this using the following command in Linux. To change the MAC Address, we need to execute a few system commands. The last three octets are Network Interface Controller Specific.

The first three octets (00:1A:3F) of the address identifies the manufacturer and is known as OUI (Organizational Unique Identifier). MAC Addresses are used to transmit packets within the network.įor example, 00:1A:3F:F1:4C:C6 is a MAC Address. MAC Address is also known as the Physical Address of a device. MAC Address is a 48-bits hardware address that is hardcoded on the Network Interface Card (NIC) at the time of manufacturing. Now, the World Wide Web (which is public) does not know who you are because your device has a private IP Address that is only recognized by your router, so the response received by the router is then given to you because the router knows your MAC Address associated with the private IP Address of your device. The router then sends this request to the World Wide Web and receives a response. For instance, when you watch a video on Youtube, you send a request for the video via your device, and this request is transmitted through your default gateway (usually through a router for a private home network). Every device needs a MAC Address to be uniquely identified by others on the network. MAC stands for Media Access Control Address. Each of these electronic gadgets has its own MAC Address. We all use various electronic gadgets such as smartphones, desktops, laptops, tablets, and many more to browse the internet, for entertainment, among other tasks. To learn how to change the MAC Address, it is essential to learn about what a MAC Address is.
