Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get MAC address in java

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to get the MAC address in java, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

What is a Mac address?

The Mac address is the address used in the media access layer. In popular terms, it is the physical address of the network card. Today's Mac address is generally 6-byte 48bit (in the early days, there was a 2-byte 16bit Mac address).

The first 24 places are the address of the manufacturer applied for by the manufacturer to IEEE (this costs money! It is said that it takes 1000 dollars to buy an address block. The last 24 places will be decided by the manufacturers themselves. (the early 2-byte ones do not need to be applied)

What is the connection and difference between IP address and Mac address

As we all know, many computers are connected by setting up a local area network first, and then connecting to the Internet through a switch (this is the case with the campus network in universities). Each user is then assigned a fixed IP address, which is centrally managed by the management center, so that for ease of management, it is necessary to use the Mac address to identify the user, prevent confusion and clarify responsibility (such as cybercrime). In addition, there is a difference between IP address and Mac address, although they are one-to-one correspondence in the local area network. The IP address is the address specified according to the current IPv4 standard, which is easy to remember without hardware restrictions, while the Mac address is the physical address of the network card, which has something to do with the hardware and is more difficult to remember.

How to know your Mac address

There are many and simple methods. Two commonly used methods are introduced here, which are available in Win9x: WinIPcfg, and in 2000 and XP using IPconfig-all. If you have assigned IP to your network card, you can also use nbtstat-A's own IP as shown below, which can only be used under 2000/XP.

How to get other people's Mac

In fact, as mentioned above, 2000/XP users can use the nbtstat-An IP address (you can get something else, but don't learn bad). In addition, in the same local area network, you can use ping IP or ping hostname, and then use arp-a to get.

How to modify your Mac address

The Mac address is saved in the EPROM of the network card, and the address in the memory can be changed through the modification program provided by the network card manufacturer. Even if the network card does not have such a setting, we can modify it indirectly. Generally, the source Mac address of the packet sent out by the network card is not written by the network card itself, but provided by the application, but in the usual implementation, the application first gets the Mac address from the network card. This Mac is used as the source Mac every time it is sent. In Windows, the Mac of the network card is saved in the registry, and the actual use is also extracted from the registry, so you can simply change the Mac as long as you modify the registry.

Modify in Win9x:

Open the registry editor. Under HKEY_LOCAL_MacHINE\ SYSTEM\ CurrentControlSet\ Service\ Class\ Net, modify the 00000 Win2000/XP 0001rec 0002 editor: also open the registry editor.

The DriverDesc in HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Control\ Class\ 4D36E970-E325-11CE-BFC1-08002BE10318, if found in 0000, add a string variable under 0000, named "NetworkAddress", and the value is the Mac address to be set, for example: 000102030405

Just restart it after you have done the above.

Modifications under Linux:

1. The network card device must be turned off, otherwise the system will be reported to be busy and cannot be changed.

The command is: "ifconfig eth0 down"

two。 Modify the Mac address, which is easier than the modification in Windows.

The command is: "ifconfig eth0 hw ether 00? AA? BB? CC? DD? EE"

3. Re-enable the network card

The change of the Mac address of the "ifconfig eth0 up" network card is completed.

There are also many software that provide the ability to modify Mac addresses, such as Mac2001

So since both IP and Mac addresses can be changed, how to defend them? Through simple switch port binding (the port's Mac table uses static table items), you can prevent the embezzlement of modified Mac addresses when only one host is connected to each switch port. If it is a layer 3 device, it can also provide: the binding of switch port-IP-Mac to prevent modified Mac IP embezzlement, this method is more effective! There are also some methods, such as configuring the VLAN of the switch, using user authentication and so on, which are slightly complicated and do not waste much ink again.

Get it by calling the dos command

Import java.io.*; public class Test {public static void main (String [] args) {try {Process process = Runtime.getRuntime (). Exec ("ipconfig / all"); InputStreamReader ir = new InputStreamReader (process. GetInputStream ()); LineNumberReader input = new LineNumberReader (ir); String line; while ((line = input.readLine ())! = null) if (line.indexOf ("Physical Address") "0) {String MACAddr = line.substring (line.indexOf ("-")-2); System.out.println (" MAC address = ["+ MACAddr +"] ");} catch (java.io.IOException e) {System.err.println (" IOException "+ e.getMessage ()) } Thank you for reading this article carefully. I hope the article "how to get an MAC address in java" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report