问题
i am writing a network utility program(for windows) in java.. i want to change/spoof the mac address of my network adapter.. how do i do that? it would be great if there is any method to do this work..
my approach is going like this by executing three commands..
//Disable network adapter netsh interface set interface name="Local Area Connection" admin=DISABLED
//this is what im not getting.. lets say i want my new spoofed address to be 00112233445566, how to do that...? didnt find any cmd command for changing mac address.. need your help here in finding if there is any cmd statement or any java method that does the job
//Enable network adapter netsh interface set interface name="Local Area Connection" admin=ENABLED
thanks, will be waiting for your help :)
回答1:
After messing with this a bit, I found an easy way to do this. Windows stores the spoofed MAC at this location in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002BE10318}\0007
by the name "NetworkAddress"="00E04D18XXXX"
I messed with cmd
to see if there was any way to edit the registry using cmd; the below command does the job perfectly
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007 /t REG_SZ /v NetworkAddress /d XXXXXXXXXXXX /f
Then this would be your Java code:
mac = textField.getText();
String commandChangeMac = "reg add HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\0007 /t REG_SZ /v NetworkAddress /d " + mac + " /f";
obj.executeCommand(commandChangeMac);
回答2:
Write your own subclass of SocketImpl which will need to use JNI code for raw sockets. Note that raw sockets will require privileged operations on most OS's.
回答3:
String mac = "2d345678U987";
Process p = Runtime
.getRuntime() .exec("cmd /c start cmd.exe /K \" \"reg add HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\0007 /t REG_SZ /v NetworkAddress /d " + mac + " /f ");
来源:https://stackoverflow.com/questions/28354386/how-to-spoof-mac-address-using-java-code