?? gethostname.java
字號:
import java.net.Socket;
import java.net.InetAddress;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
/**
* Created by IntelliJ IDEA.
* User: ${040421220 鄭天南}
* Date: 2007-4-12
* Time: 20:27:41
*/
public class getHostName
{
public static void main(String[] args)
{
try
{
Socket s=new Socket("127.0.0.1",6629);
InetAddress address=s.getLocalAddress();
//getHostName
System.out.println(address.getHostName());
//getMACaddress
MACAddress mac=new MACAddress();
System.out.println(mac.getMACAddress());
}
catch(Exception ex)
{
}
}
}
class MACAddress {
public MACAddress() {
}
public String getMACAddress() {
String address = "";
String os = System.getProperty("os.name");
if (os != null && os.startsWith("Windows")) {
try {
String command = "cmd.exe /c ipconfig /all";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br =
new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
return address.trim();
} catch (IOException e) {}
}
return address;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -