gpt4 book ai didi

Java - MacAddressApplet 更新到 8u45 后不工作

转载 作者:太空宇宙 更新时间:2023-11-04 13:56:48 25 4
gpt4 key购买 nike

在我的一个 Web 应用程序中,我正在使用 MacAddressApplet,可以在 here 中找到它。 .

在 Java 8u31 之前一切都运行良好。自从今天更新到 Java 8u45 后,它就停止工作了。从小程序检索 MAC 地址的函数调用现在返回未定义。

有什么建议吗?

根据“请求”这里的代码:(即使我在上面链接到它)

/*
* Copyright (c) 2008-2010. Agwego Enterprises Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* If you modify this software a credit would be nice
*/

import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.util.Enumeration;
import java.util.ArrayList;
import java.applet.Applet;

public class MacAddressApplet extends Applet
{
public static String sep = ":";
public static String format = "%02X";

/**
* getMacAddress - return the first mac address found
* separator - byte seperator default ":"
* format - byte formatter default "%02X"
*
* @param ni - the network interface
* @return String - the mac address as a string
* @throws SocketException - pass it on
*/
public static String macToString( NetworkInterface ni ) throws SocketException
{
return macToString( ni, MacAddressApplet.sep, MacAddressApplet.format );
}

/**
* getMacAddress - return the first mac address found
*
* @param ni - the network interface
* @param separator - byte seperator default ":"
* @param format - byte formatter default "%02X"
* @return String - the mac address as a string
* @throws SocketException - pass it on
*/
public static String macToString( NetworkInterface ni, String separator, String format ) throws SocketException
{
byte mac [] = ni.getHardwareAddress();

if( mac != null ) {
StringBuffer macAddress = new StringBuffer( "" );
String sep = "";
for( byte o : mac ) {
macAddress.append( sep ).append( String.format( format, o ) );
sep = separator;
}
return macAddress.toString();
}

return null;
}

/**
* getMacAddressInternal - return the first mac address found
*
* @return the mac address or undefined
*/
protected static String getMacAddressInternal()
{
try {
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();

// not all interface will have a mac address for instance loopback on windows
while( nis.hasMoreElements() ) {
String mac = macToString( nis.nextElement() );
if( mac != null && mac.length() > 0 )
return mac;
}
} catch( SocketException ex ) {
System.err.println( "SocketException:: " + ex.getMessage() );
ex.printStackTrace();
} catch( Exception ex ) {
System.err.println( "Exception:: " + ex.getMessage() );
ex.printStackTrace();
}

return "undefined";
}

/**
* getMacAddressesJSON - return all mac addresses found
*
* @return a JSON array of strings (as a string)
*/
protected static String getMacAddressesJSONInternal()
{
try {
String macs [] = getMacAddresses();

String sep = "";
StringBuffer macArray = new StringBuffer( "['" );
for( String mac: macs ) {
macArray.append( sep ).append( mac );
sep = "','";
}
macArray.append( "']" );

return macArray.toString();
} catch( Exception ex ) {
System.err.println( "Exception:: " + ex.getMessage() );
ex.printStackTrace();
}

return "[]";
}

/**
* getMacAddresses - return all mac addresses found
*
* @return array of strings (mac addresses) empty if none found
*/
public static String [] getMacAddresses()
{
try {
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();

ArrayList<String> macs = new ArrayList<String>();
while( nis.hasMoreElements() ) {
String mac = macToString( nis.nextElement() );
// not all interface will have a mac address for instance loopback on windows
if( mac != null ) {
macs.add( mac );
}
}
return macs.toArray( new String[macs.size()] );
} catch( SocketException ex ) {
System.err.println( "SocketException:: " + ex.getMessage() );
ex.printStackTrace();
} catch( Exception ex ) {
System.err.println( "Exception:: " + ex.getMessage() );
ex.printStackTrace();
}

return new String[0];
}

/**
* getMacAddresses - return all mac addresses found
*
* @param sep - use a different separator
*/
public static void setSep( String sep )
{
try {
MacAddressApplet.sep = sep;
} catch( Exception ex ) {
// don't care
}
}

/**
* getMacAddresses - return all mac addresses found
*
* @param format - the output format string for bytes that can be overridden default hex.
*/
public static void setFormat( String format )
{
try {
MacAddressApplet.format = format;
} catch( Exception ex ) {
// don't care
}
}

/**
* Wrap the privilege access to our internal method
*/
private final class MacAddressService implements PrivilegedAction<String>
{
public String run()
{
return getMacAddressInternal();
}
}

/**
* Wrap the privilege access to our internal method
*/
private final class MacAddressesJSONService implements PrivilegedAction<String>
{
public String run()
{
return getMacAddressesJSONInternal();
}
}


/**
* getMacAddress - return the first mac address found
*
* @return the mac address or undefined
* @throws java.security.PrivilegedActionException ex
*/
public String getMacAddress() throws PrivilegedActionException
{
return AccessController.doPrivileged( new MacAddressService() );
}

/**
* getMacAddress - return the first mac address found
*
* @return the mac address or undefined
* @throws java.security.PrivilegedActionException ex
*/
public String getMacAddressesJSON() throws PrivilegedActionException
{
return AccessController.doPrivileged( new MacAddressesJSONService() );
}

public static void main( String... args )
{
MacAddressApplet ma = new MacAddressApplet();

try {
System.err.println( " MacAddress = " + ma.getMacAddress() );
System.err.println( " MacAddresses JSON = " + ma.getMacAddressesJSON() );

} catch( PrivilegedActionException ex ) {
System.err.println( ex );
ex.printStackTrace();
}
}
}

被调用的函数是:

getMacAddresses()

[编辑]该 jar 使用以下 list 进行签名:

Permissions: all-permissions
Codebase: *
Application-Name: CelluPOS

最佳答案

您需要授予自己java.net.NetPermission: getNetworkInformation。

关于Java - MacAddressApplet 更新到 8u45 后不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29739091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com