public static String getLocalAddress() {
try {
// Traversal Network interface to get the first non-loopback and non-private address
Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
ArrayList<String> ipv4Result = new ArrayList<String>();
ArrayList<String> ipv6Result = new ArrayList<String>();
while (enumeration.hasMoreElements()) {
final NetworkInterface networkInterface = enumeration.nextElement();
final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
while (en.hasMoreElements()) {
final InetAddress address = en.nextElement();
if (!address.isLoopbackAddress()) {
if (address instanceof Inet6Address) {
ipv6Result.add(normalizeHostAddress(address));
} else {
ipv4Result.add(normalizeHostAddress(address));
}
}
}
}
// prefer ipv4
if (!ipv4Result.isEmpty()) {
for (String ip : ipv4Result) {
if (ip.startsWith("127.0") || ip.startsWith("192.168")) {
continue;
}
return ip;
}
return ipv4Result.get(ipv4Result.size() - 1);
} else if (!ipv6Result.isEmpty()) {
return ipv6Result.get(0);
}
//If failed to find,fall back to localhost
final InetAddress localHost = InetAddress.getLocalHost();
return normalizeHostAddress(localHost);
} catch (Exception e) {
log.error("Failed to obtain local address", e);
}
return null;
}
相关推荐
Java实现获取本地IP地址的完整小程序
IP地址(Internet Protocol Address)是分配给网络中每一台设备的数字标识符,用于在网络中唯一标识和定位设备。其核心作用包括:寻址与路由:确保数据包能够从源主机正确传输到目标主机。身份识别:在网络通信中识别通信双方的身份。网络管理:便于网络管理员进行IP分配、访问控制和故障排查。目前广泛使用的IP协议版本包括IPv4和IPv6。的构造函数是受保护的(protected),这意味着我们不能直接通过来创建实例。
java获取本机ip的方法
Java中有一个类叫 Application,可以用来获取本机 ip,也可以用来获取网络连接的信息,例如网络上有什么主机、需要访问本机的主机名等。动态 IP是指路由器根据一定的规则,动态分配 IP地址,当主机从一个路由器转发数据时,路由器将这个 IP地址保存在自己的内存中,并在下一个周期根据该 IP地址计算出下一个周期的 IP地址。4.将获取到的本机 ip地址和 test类绑定,如果需要访问外部的主机,那么需要使用动态 IP协议来访问,如果采用静态 IP协议,就可以获取到外部主机的 IP地址。
数字后端DRC Violation定位与自动化修复:Innovus与Calibre协同实战
设计规则检查(DRC)是芯片tapeout前确保版图可制造性的关键验证环节。在数字后端流程中,Calibre作为signoff级物理验证工具,会依据代工厂SVRF规则文件对GDS进行严格几何检查;而Innovus则提供快速迭代的in-design DRC反馈。两者协同成为工程师定位violation、保障流片成功的主流工作流。面对成千上万条DRC violation,高效的定位与分类思路、跨工具映射技巧,以及基于Tcl脚本的自动化修复方法,能大幅缩短物理验证周期。本文从DRC的分层定位出发,结合Innovu
Java实现Ip地址获取
Java实现Ip地址获取
国民技术N32G45X低功耗问题之更改全局变量和栈在RAM中的地址
最近项目中用的MCU是国民技术的N32G45X,MCU的资源很丰富,RAM也很大,配套的库和例程也比较全,用起来还是不错的,但是在调试低功耗的时候还是费了不少劲。 首先由于项目低功耗需要,只能选择停机模式2(STOP2)。根据数据手册的描述,在此模式下外部低速时钟开启, RTC运行, R-SRAM保持,所有I/O状态保持,独立看门狗处于关闭状态,25℃的条件下电流为10个微安。 用的这款MCU的RAM是144KB,分为SRAM(128KB)和R-SRAM( Retention SRAM – 16KB),如果
Android 桌面小组件 AppWidgetProvider
桌面小组件,绝对是小程序中的小程序,说白了就是任何复杂一丁点的操作都适合做成桌面小组件。所以这里采用的演示的例子,就只有一个白色圆角背景,外加一个文本框,显示文字。小组件的教程网上一搜一大堆,所以我这里主要就是介绍一些坑的地方,跟大致处理流程,具体细节还得看其他大神的骚操作。
java获取登陆用户ip方法
在 Java环境中,获取动态链接库的 api一般都是通过 JDK提供的 api来实现的,当你需要获取某个动态链接库的 ip时,可以在 JDK的环境中找到对应的 api进行使用,下面以java.io中的 api为例: 1.进入 JDK,打开开发者工具 2.在搜索栏中输入java.io 3.点击搜索结果中的 java. exe 4.选择 java. exe下载安装包 5.点击安装,安装成功后会出现 java. exe的路径和 api名称,这时就需要去 Java官网找对应的 api文件进行安装了。
【UE5】【蓝图】 LevelSequence 动画播放与暂停
最近有些工作,在研究UE5 蓝图的LevelSequence,来制作一些简单动画。做个笔记,记录一下动画更换绑定actor的操作,以及动画播放后如何暂停和继续。
java 获取网卡 ip地址
JAVA获取本地ip /** * 获取本地网卡ip * @return */ public static String getLocalAddress() { try { // Traversal Network interface to get the first non-loopback and non-priv...
[xboard-real6410]39 real6410中的BL1和BL2实验及流程分析
文章目录uboot控制uboot 流程uboot加载kernel uboot控制 uboot 流程 uboot加载kernel
12、硬件工程师笔试面试——MOS管(2025版本)
在设计和测试过程中,可以参考相关的EMC测试标准和指南,如CE认证EMC电磁兼容测试介绍 和电磁兼容性(EMC)测试方法与整改指南 ,以及电磁兼容(EMC)的标准与测试内容 ,来确保MOSFET的EMC性能符合行业标准。在高频应用中,MOSFET的开关速度对电路的整体性能至关重要。是一款高电压同步N沟道MOSFET驱动器,具有自举电源电压至114V的能力,宽VCC电压范围,自适应贯通保护功能,以及高达1.4A的峰值顶端栅极上拉电流,适用于分布式电源架构、汽车电源、高密度电源模块和电信系统等应用。
java获取本地ip地址(Windows和Linux通用)
package com.trs.web2frame.start; import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; /** * 获取本地ip地址的方法(Linux环境和Java通用) * @ver...
《信息化项目文档模板十二——业务需求新增/变更审批确认表 》
系列文章目录 《信息化项目文档模板一——项目需求说明书》 《信息化项目文档模板二——项目启动会文档模板》 《信息化项目文档模板三——会议纪要模板》 《信息化项目文档模板四——系统项目蓝图设计模板》 《信息化项目文档模板五——系统详细设计模板》 《信息化项目文档模板六——系统详细设计模板》 《信息化项目文档模板七——系统开发计划模板》 《信息化项目文档模板八——系统功能测试模板》 《信息化项目文档模板九——系统压力测试模板》 《信息化项目文档模板十——系统推广上线计划模板》 《信息化项目文档模板十一——系统用
java获取本地ip地址
使用java的InetAddress可以很简单的获取本地的ip地址 package Test; import java.net.InetAddress; import java.net.UnknownHostException; import javax.management.StringValueExp; public class GetIP { /** * 获取本地ip * @para...
YOLO项目从零开始:超详细运行教程(图文保姆级教学)
至此,我们已经完整跑通了YOLO项目的安装与启动流程,无论你是零基础小白还是刚入门的AI新兵,只要按部就班操作,也能轻松实现目标检测项目的落地。
win10 跳过U8环境检测的IE WebControls.rar
win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。
用Java获取本地的多个IP地址
翻API翻出来的,拿出来晒晒。。。特别适用于获取本地的多个IP地址 import java.net.InetAddress;import java.net.NetworkInterface;import java.net.SocketException;import java.net.UnknownHostException;import java.util.Enume
SAP B1中文培訓教材_SDK
公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说
Java获取本地IP地址的值
import java.net.InetAddress; import java.net.UnknownHostException; public class ipget { //构造方法私有 private ipget(){} //静态修饰 public static String address() throws UnknownHostException { InetAddress addr = InetAddress.getLocalHost();
计算机控制技术及应用
《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
java mac地址转换_java根据本地IP获取mac地址的方法
本文实例为大家分享了java根据本地ip获取mac地址的具体代码,供大家参考,具体内容如下import java.net.inetaddress;import java.net.networkinterface;import java.net.socketexception;import java.net.unknownhostexception;public class macaddress {...
Java获取本地IP和mac地址
请注意,获取MAC地址可能需要具有适当的权限,并且在某些情况下可能无法获取到准确的MAC地址。这段代码将打印出请求端的IP地址和MAC地址。
java获得本地ip地址吗_java 获取的是本地的IP地址
1 public static void main(String[] args) {2 try {3 InetAddress address = InetAddress.getLocalHost();//获取的是本地的IP地址 //PC-20140317PXKX/192.168.0.1214 String hostAddress = ...
JAVA获取本地ip地址
JAVA获取本地ip地址 因为项目中正好用到本地IP地址,然后上网搜了一下,看写的不是特别详细,所以在这里补充一下。 首先获取到本地设备的名称和IP InetAddress inetAddress = InetAddress.getLocalHost(); 然后输出为: Q4ER6ZHVM5NWJ2X/192.168.2.23 如果要用到程序中,则需要将这个转换为String类
java 根据ip获取mac_java根据本地IP获取mac地址的方法
本文实例为大家分享了java根据本地IP获取mac地址的具体代码,供大家参考,具体内容如下import java.net.InetAddress;import java.net.NetworkInterface;import java.net.SocketException;import java.net.UnknownHostException;public class MacAddress {...
java 根据mac地址获取ip_java根据本地IP获取mac地址的方法
本文实例为大家分享了java根据本地IP获取mac地址的具体代码,供大家参考,具体内容如下import java.net.InetAddress;import java.net.NetworkInterface;import java.net.SocketException;import java.net.UnknownHostException;public class MacAddress {...
java获取本地IP地址集合包括虚拟机的ip
public static ArrayList<String> getLocalIpAddr() { ArrayList<String> ipList = new ArrayList<String>(); InetAddress[] addrList; try { ...
利用Java获取本地IP地址
package new_world1; import java.io.; import java.net.; //获取IP地址 public class spurs_ping145 { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub if(args.leng...
1007



被折叠的 条评论
为什么被折叠?



