- 浏览: 543116 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (339)
- JavaBase (27)
- J2EE (70)
- Database (22)
- Spring (3)
- struts1.x (6)
- struts2.x (16)
- Hibernate (10)
- IBatis (4)
- DWR (1)
- SSH (5)
- Oracle (31)
- HTML (12)
- javascript (11)
- Thinking (3)
- Workflow (5)
- Live (13)
- Linux (23)
- ExtJS (35)
- flex (10)
- php (3)
- Ant (10)
- ps (1)
- work (2)
- Test (1)
- Regular Expressions (2)
- HTTPServer (2)
- 方言 (1)
- 生活 (2)
- Sybase PowerDesigner (0)
最新评论
-
mikey_5:
非常感谢楼主的分享,<parameter propert ...
Check the output parameters (register output parameters failed) IN Ibatis -
影子_890314:
我现在也有这个错误,求解!
Check the output parameters (register output parameters failed) IN Ibatis -
358135071:
学习了,感谢分享!
使用hibernate 代替 mysql 中 limit 進行分頁 -
wjpiao:
你下面的“正确的映射”里面不是还是有number类型吗?
Check the output parameters (register output parameters failed) IN Ibatis -
zh_s_z:
很有用!弄一份吧!
Oracle数据库分区表操作方法
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.NetworkInterface;
import java.util.Enumeration;
public class MACUtil {
// 返回一个字节的十六进制字符串
public static String hexByte(byte b) {
String s = "000000" + Integer.toHexString(b);
return s.substring(s.length() - 2);
}
/**
* JDK1.6新特性获取网卡MAC地址
*/
public static void getMac() {
try {
Enumeration<NetworkInterface> el = NetworkInterface
.getNetworkInterfaces();
while (el.hasMoreElements()) {
byte[] mac = el.nextElement().getHardwareAddress();
if (mac == null) {
continue;
}
StringBuilder builder = new StringBuilder();
for (byte b : mac) {
builder.append(hexByte(b));
builder.append("-");
}
builder.deleteCharAt(builder.length() - 1);
System.out.println(builder);
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* 原始的获取网卡MAC地址
*/
public static void getMacOnWindow() {
try {
String mac = null;
Process process = Runtime.getRuntime().exec("ipconfig /all");
BufferedReader buffer = new BufferedReader(new InputStreamReader(
process.getInputStream()));
for (String line = buffer.readLine(); line != null; line = buffer
.readLine()) {
System.out.println(line);
int index = line.indexOf("Physical Address");
if (index <= 0) {
continue;
}
mac = line.substring(index + 36);
break;
}
buffer.close();
process.waitFor();
System.out.println(mac);
} catch (Exception exception) {
exception.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
System.out.println("通过调用DOS命令获得本机器的所有的网卡MAC如下:");
getMacOnWindow();
System.out.println("通过JDK获得本机器的所有的网卡MAC如下:");
getMac();
}
}
//------------------------------------------------------------------------------------------------------------------------------
package com.jtosa.util;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.text.ParseException;
import java.util.StringTokenizer;
import java.io.BufferedInputStream;
public class MACUtil {
private final static int MACADDR_LENGTH = 17;
private final static String WIN_OSNAME = "Windows";
private final static String WIN_MACADDR_REG_EXP = "^[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}$";
private final static String WIN_MACADDR_EXEC = "ipconfig /all";
public final static String getMacAddress() throws IOException {
String os = System.getProperty("os.name");
try {
if (os.startsWith(WIN_OSNAME)) {
return winMacAddress(winIpConfigCommand());
}
// 下面是其它的操作系统的代码,省略了!
// LINUX --> else if (os.startsWith("Linux")) {
//
// Process p = Runtime.getRuntime().exec("ifconfig");
// MAC OSX --> else if(os.startsWith("Mac OS X")) {
//
// Process p = Runtime.getRuntime().exec("ifconfig");
else {
throw new IOException("OS not supported : " + os);
}
} catch (ParseException e) {
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
private final static String winMacAddress(String ipConfigOutput)
throws ParseException {
String localHost = null;
try {
localHost = InetAddress.getLocalHost().getHostAddress();
} catch (java.net.UnknownHostException ex) {
ex.printStackTrace();
throw new ParseException(ex.getMessage(), 0);
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigOutput, "\n");
String lastMacAddress = null;
while (tokenizer.hasMoreTokens()) {
String line = tokenizer.nextToken().trim();
// see if line contains IP address
if (line.endsWith(localHost) && lastMacAddress != null) {
return lastMacAddress;
}
// see if line contains MAC address
int macAddressPosition = line.indexOf(":");
if (macAddressPosition <= 0)
continue;
String macAddressCandidate = line.substring(macAddressPosition + 1)
.trim();
if (winIsMacAddress(macAddressCandidate)) {
lastMacAddress = macAddressCandidate;
continue;
}
}
ParseException ex = new ParseException("cannot read MAC address from ["
+ ipConfigOutput + "]", 0);
ex.printStackTrace();
throw ex;
}
private final static boolean winIsMacAddress(String macAddressCandidate) {
if (macAddressCandidate.length() != MACADDR_LENGTH)
return false;
if (!macAddressCandidate.matches(WIN_MACADDR_REG_EXP))
return false;
return true;
}
private final static String winIpConfigCommand() throws IOException {
Process p = Runtime.getRuntime().exec(WIN_MACADDR_EXEC);
InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
StringBuffer buffer = new StringBuffer();
for (;;) {
int c = stdoutStream.read();
if (c == -1)
break;
buffer.append((char) c);
}
String outputText = buffer.toString();
stdoutStream.close();
return outputText;
}
public final static void main(String[] args) {
try {
System.out.println("MAC ADDRESS");
System.out.println(" OS : "
+ System.getProperty("os.name"));
System.out.println(" IP/Localhost: "
+ InetAddress.getLocalHost().getHostAddress());
System.out.println(" MAC Address : " + getMacAddress());
} catch (Throwable t) {
t.printStackTrace();
}
}
}
发表评论
-
Moto官方GMS谷歌服务套件For XT800+下载和使用教程
2011-05-21 22:03 3998MOTOXT800+ ANDROID ROM address: ... -
barcode4j
2011-05-14 17:34 975project net address: htt ... -
org.logicalcobwebs.proxool 连接池异常
2011-05-09 10:02 76892011/05/09 09:59:44:695 ERROR [ ... -
Spring JDBC 调用 procedure
2011-03-25 16:12 1338import java.sql.CallableStateme ... -
JDBC Call MySQL Proc
2011-03-25 15:10 1025MySQL PROC : ------------- ... -
Axis 开发WebService
2011-03-14 16:11 892net address : http://blog.cs ... -
java 内存查看软件_Jprofiler
2011-03-04 14:34 892java 内存查看软件(Eclipse plugin): ... -
了解 Eclipse 插件如何使用 OSGi
2011-02-18 09:39 981http://www.ibm.com/developerwor ... -
tomcat out of Memory error
2011-01-28 17:03 1029net address: http://www.iteye.c ... -
bak_
2010-12-30 17:48 810weblog address: http://kenwubl ... -
jsp tag page plugin
2010-12-09 15:31 899jsp tag page plugin: http://ww ... -
page cache set
2010-12-02 17:03 841response.setHeader("Ca ... -
properties file editor
2010-11-28 14:26 880net address(多种语言在同一个表格中,容易排除遗漏属 ... -
判断浏览器的语言
2010-11-26 17:43 859*.jsp page : <% Lan ... -
属性文件编辑器
2010-11-26 14:43 955在此想和大家分享一个不错的编写properties文件的Ecl ... -
google-api-translate-java
2010-11-14 17:51 809// http://code.google.com/p/go ... -
regex in java
2010-11-14 16:06 909Pattern类: 例子: Pat ... -
EHCache 配置详解
2010-10-13 17:22 10553EHCache 是一个纯java 的在进程中的缓存 ... -
displaytag jsp paging tag
2010-10-13 10:04 874displaytag :jsp paging tag ... -
Spring_Recipes code
2010-09-29 23:47 711code source: http://www.apress ...
相关推荐
func getLocalIPAddress() -> String? { var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_zero: [0; 8]) zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress)) ...
function GetLocalIPAddress: string; var HostEntry: THostEntry; begin Result := ''; if GetHostByName('localhost') = nil then Exit; HostEntry := Gethostbyname('localhost'); if HostEntry <> nil ...
例如,`System.Net.Dns.GetHostEntry("localhost")`或`IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName())`方法可以获取到本地主机的所有IP地址。这些方法会返回一个IP地址数组,你可以遍历这个数组...
MAC地址(Media Access Control Address)则是物理网络接口的硬件地址,用于局域网内的设备识别,通常为6个字节的12位十六进制数。 在JAVA中,我们可以使用java.net包中的InetAddress类来获取本地IP地址。这个类...
string macAddress = Request.Headers["X-Mac-Address"]; // 验证MAC地址并处理逻辑 return Content(macAddress); } ``` 在实际应用中,考虑到隐私保护和安全问题,直接获取客户端的MAC地址可能不符合最佳实践。...
PhysicalAddress macAddress = NetworkInterface.GetAllNetworkInterfaces() .Where(nic => nic.OperationalStatus == OperationalStatus.Up) .Select(nic => nic.GetPhysicalAddress()) .FirstOrDefault(); ``` ...
if (getaddrinfo("localhost", NULL, &hints, &result) != 0) { std::cerr << "getaddrinfo failed: " () ; WSACleanup(); return 1; } for (addrinfo* r = result; r; r = r->ai_next) { char ipstr[INET6_...
System.out.println("Your Mac Address is: " + mytool.getMACAddress()); } // 取得 LOCALHOST 的 IP 地址 public InetAddress getMyIP() { try { myIPaddress = InetAddress.getLocalHost(); } catch ...
对于其他编程语言,如JavaScript、Go、Ruby等,也有各种第三方库可以帮助获取MAC地址,如Node.js中的`macaddress`模块,Go语言的`golang.org/x/sys/unix`包等。 5. **网络驱动程序**: MAC地址通常由网络驱动程序...
如果需要获取本地机器的IP地址,可以调用`gethostbyname("localhost")`或`getaddrinfo("127.0.0.1", "0", ...)`。对于IPv4和IPv6的支持,可以使用`gethostbyaddr`函数,传入网络接口的IP地址。 至于MAC地址,它在...
void GetLocalIPAddress() { PIP_ADAPTER_INFO pAdapterInfo = NULL; DWORD dwBufLen = 0; // 获取所需缓冲区大小 GetAdaptersInfo(NULL, &dwBufLen); pAdapterInfo = (IP_ADAPTER_INFO*)malloc(dwBufLen); ...
在MFC中,你可以使用`WSAStartup`初始化Winsock,然后使用`gethostbyname`或`getaddrinfo`函数来获取IP地址。以下是一个简单的例子: ```cpp #include #include void GetIPAddress() { WSADATA wsaData; if ...
IP地址(Internet Protocol Address)是互联网上的每个设备独一无二的标识,它由32位二进制数组成,通常以点分十进制形式表示,如192.168.1.1。在Java中,我们可以使用内置的`java.net`包来处理与网络相关的操作,...
如果需要枚举MAC地址,可以查询`Win32_NetworkAdapter`类,其`MACAddress`属性包含了物理地址信息。 总结,通过以上步骤,我们可以使用VC++和WMI来枚举局域网内的计算机IP和名称。实际应用中,还需要根据具体需求...
You can get a public key‘s fingerprint by running % ssh-keygen -F publickey.pub on the keyfile. Are you sure you want to continue connecting (yes/no)? Yes Host key saved to /home/jsmith/.ssh2/host...
循环遍历查询结果,获取`MACAddress`属性,即网卡的物理地址,通常用于网络通信中的硬件识别。同样,在找到第一个非空MAC地址后停止循环。 4. **获取可用串口**: `getport`函数用于查找尚未被IIS使用的端口号。这...
String ipAddress = localHost.getHostAddress(); ``` 当用户通过ADSL或其他宽带拨号方式连接互联网时,获取的IP地址通常为动态分配,每次拨号连接可能会改变。这时,我们可以通过以下方式获取: 1. 拨号软件...
Invoke-WmiMethod -Class Win32_NetworkAdapterConfiguration -ComputerName $ipAddress -Name SendARP -ArgumentList ($macAddress, $ipAddress) ``` 一旦设备被唤醒,你可以使用Powershell的PSRemoting功能来...
在命令行中导航到Glassfish的bin目录,然后运行相应的启动脚本(对于Windows系统通常是`asadmin start-domain`,对于Linux或Mac系统则是`./asadmin start-domain`)。 步骤二:创建或导入域 在首次部署应用之前,...