如何在Windows 10上使用Java识别wifi或手机连接
我正在开发一个Java应用程序,运行在Windows10Prof.MicrosoftSurface Pro平板电脑和SIM卡上。该应用程序提供多种更新机制,用于更新EFB电子飞行包应用程序集合、生成报告、将其发送到远程Alfresco服务器,并为用户和公司提供文档生命周期。有小的和大的更新,这意味着一个更新处理大约300MB,另一个是1.8GB。现在,我们也将实施手机更新,以防无线网络失效。现在,我花了很多时间从Java的角度来区分wifi和蜂窝连接。我找到了一个.net-API来实现这一点,但没有找到相应的Java方法。当然,我可以构建一个.net二进制文件,并从Java调用它来存储一个包含答案的文件,但这看起来很难看。在Windows 10上,有没有人有过使用Java区分手机和Wifi的经验?欢迎任何提示。此代码使用java.net.interfacedAddress来检查是否存在接口。从这一点来看,连接类型很容易从.getDisplayName方法中检测出来。我修改了源代码如何在Windows 10上使用Java识别wifi或手机连接,java,windows,wifi,cellular-network,Java,Windows,Wifi,Cellular Network,我正在开发一个Java应用程序,运行在Windows10Prof.MicrosoftSurface Pro平板电脑和SIM卡上。该应用程序提供多种更新机制,用于更新EFB电子飞行包应用程序集合、生成报告、将其发送到远程Alfresco服务器,并为用户和公司提供文档生命周期。有小的和大的更新,这意味着一个更新处理大约300MB,另一个是1.8GB。现在,我们也将实施手机更新,以防无线网络失效。现在,我花了很多时间从Java的角度来区分wifi和蜂窝连接。我找到了一个.net-API来实现这一点,但
没有办法以本机方式使用Java。您可以使用exec调用powershell或其他功能。但这将是一个非常混乱的解决方案。我的建议是用c语言编写,并使用JNI调用它。这不是一个完整的答案,因为我不知道如何实现您想要的,但是java.net.NetworkInterface类可以提供关于接口的信息—它们的名称,它们是否处于活动状态,等等,如果您可以控制他们是否在内部控制设备,从而知道接口的名称,您可能不需要使用.NET就可以对其进行黑客攻击binary@FrenchFigaro这似乎是可行的…我实际上可以过滤现有的接口来查找那些正在启动的接口…而且wifi和蜂窝接口从来不会像我们的windows配置那样同时启动。我会尽快向你们两位提供消息来源,非常感谢!
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import org.apache.commons.lang.StringUtils;
public class networkConnectionTeller {
public static boolean isNetworkRunningViaCellular() throws SocketException {
String s = "";
// NetworkInterface implements a static method that returns all the
//interfaces on the PC,
// which we add on a list in order to iterate over them.
ArrayList interfaces =
Collections.list(NetworkInterface.getNetworkInterfaces());
s += ("Printing information about the available interfaces...\n");
for (Object ifaceO : interfaces) {
NetworkInterface iface = (NetworkInterface) ifaceO;
// Due to the amount of the interfaces, we will only print info
// about the interfaces that are actually online.
if (iface.isUp() &&
!StringUtils.containsIgnoreCase(iface.getDisplayName(), "loopback")) {
//Don`t want to see software loopback interfaces
// Display name
s += ("Interface name: " + iface.getDisplayName() + "\n");
// Interface addresses of the network interface
s += ("\tInterface addresses: ");
for (InterfaceAddress addr : iface.getInterfaceAddresses()) {
s += ("\t\t" + addr.getAddress().toString() + "\n");
}
// MTU (Maximum Transmission Unit)
s += ("\tMTU: " + iface.getMTU() + "\n");
// Subinterfaces
s += ("\tSubinterfaces: " +
Collections.list(iface.getSubInterfaces()) + "\n");
// Check other information regarding the interface
s += ("\tis loopback: " + iface.isLoopback() + "\n");
s += ("\tis virtual: " + iface.isVirtual() + "\n");
s += ("\tis point to point: " + iface.isPointToPoint() + "\n");
System.out.println(s);
if (iface.getDisplayName().contains("Broadband")) {
return true;
}
}
}
return false;
}
}