java中获取当前服务器的Ip地址

java中获取当前服务器的Ip地址的方法 本篇文章主要介绍了java中获取当前服务器的Ip地址的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧 立即下载

java中获取当前服务器的Ip地址

1、tomcat是一款免费的开源Web服务器,如果部署在本地,那么对应的那么为localhost,对应地址为127.0.0.1。

         例子:可以通过http://localhost:8080/项目root值访问,也可以通过http://127.0.0.1/项目root值访问。

   如果部署在服务器(linux)系统类,则需要通过服务器的Ip地址进行访问。

2、下面说说怎么获取Ip地址:

  获取本地的Ip地址:

复制代码
 1 public static void main(String[] args) {
 2       try {
 3              InetAddress address = InetAddress.getLocalHost();//获取的是本地的IP地址 //PC-20140317PXKX/192.168.0.121
 4              String hostAddress = address.getHostAddress());//192.168.0.121            
 5              InetAddress address1 = InetAddress.getByName("www.wodexiangce.cn");//获取的是该网站的ip地址,比如我们所有的请求都通过nginx的,所以这里获取到的其实是nginx服务器的IP地 
 6              String hostAddress1 = address1.getHostAddress());//124.237.121.122 
 7              InetAddress[] addresses = InetAddress.getAllByName("www.baidu.com");//根据主机名返回其可能的所有InetAddress对象 
 8              for(InetAddress addr:addresses){ 
 9              System.out.println(addr);//www.baidu.com/14.215.177.38 
10              //www.baidu.com/14.215.177.37 
11            } 
12         } catch (UnknownHostException e) { 
13              e.printStackTrace();
14       } 
15  }
复制代码

 获取服务器的Ip地址(其他人写的)

 

复制代码
 1 /**
 2      * 获取服务器IP地址
 3      * @return
 4      */
 5     @SuppressWarnings("unchecked")
 6     public static String  getServerIp(){
 7         String SERVER_IP = null;
 8         try {
 9             Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
10             InetAddress ip = null;
11             while (netInterfaces.hasMoreElements()) {
12                 NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
13                 ip = (InetAddress) ni.getInetAddresses().nextElement();
14                 SERVER_IP = ip.getHostAddress();
15                 if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress()
16                         && ip.getHostAddress().indexOf(":") == -1) {
17                     SERVER_IP = ip.getHostAddress();
18                     break;
19                 } else {
20                     ip = null;
21                 }
22             }
23         } catch (SocketException e) {
24             // TODO Auto-generated catch block
25             e.printStackTrace();
26         }
27     
28         return SERVER_IP;
29     }
30 }
复制代码

 

基于SSM框架的农业物联网智能养殖系统中的养殖日志要求上传一张图片到服务器中。本地测试时,由于保存的路径在本地磁盘E中,所以后台直接从本地获取了资源文件。传入服务器胡,找不到该文件,估计是IP地址无法获取到,只有对应的文件路径,基于此,想设计出从服务器里读取文件信息,但是并没有成功。后来发现localhost与127.0.0.1是一致的,就想起了用服务器IP地址代替localhost完成读取操作,但本质仍然是前台界面的读取。   、。。。。待完善

NLP高频面试题(一)——Transformer的基本结构、作用和代码实现 本文详细介绍了Transformer模型的基本结构和PyTorch代码实现过程。首先解析了Transformer的核心组成部分,包括嵌入层、多头自注意力机制、位置编码、前馈神经网络、编码器和解码器等模块,并通过清晰的代码示例逐步展示了如何在PyTorch中构建完整的Transformer模型。文末提供了一个可运行的简单示例,帮助读者快速理解并实践Transformer的核心原理与实现方法。 阅读详情

相关推荐

QTabWidget动态标签页管理:从代码创建到UI设计的实战指南

本文深入探讨了QTabWidget动态标签页管理的实战技巧,涵盖从纯代码创建到UI设计器布局的两种核心方法。详细讲解了如何动态添加、插入、关闭标签页,并管理其内容与生命周期。文章还提供了标签页精细化控制、界面优化(如设置图标、样式表)以及构建简易多文档编辑器的进阶实战案例,帮助开发者灵活应对数据监控、多文档编辑等复杂界面需求。

omega的博客 865

Java中获取当前服务器的IP地址

Java中获取当前服务器的IP地址

qq_40453972的博客 1万+

Bugku中的source

进入环境后 我们首先查看源码可以得到一个flag 这肯定是个假的(已经提交过了确实是个假的) 题目提示要用Linux 这里使用的是kali 我们首先dirsearch一下这个网站 可以看到有.git文件泄露 也可以点开那个链接但是在里面没有找到flag 然后选择下载这个.git文件 然后进入这个文件夹 输入git reflog查看文件状态 可以看到有四个都有flag is here 一个一个查看git show 然后在40c6d51中发现了我们需要的fl

A272036149的博客 1011

JAVA如何获取服务器ip

在使用代理服务器时,如果想要获取代理服务器的IP地址,可以使用其他方法来实现,例如可以发送一个HTTP请求到一个公共的IP地址查询服务,然后从返回的响应中解析出代理服务器的IP地址。,该服务会返回我们的公共IP地址。为了获取正确的IP地址,可以使用其他方法来获取服务器上所有的网络接口,并遍历每个网络接口来获取对应的IP地址。该方法返回的是默认的本地地址,可能是服务器上某个网络接口的IP地址,但不一定是我们期望获取的IP地址。方法返回的是本地主机(即运行该代码的主机)的IP地址,而不是代理服务器的IP地址。

好好学习,天天向上 5854

中国境内及周边2839个站点的日降水量逐日降水数据集(1961-2022,0.1°/0.25°/0.5°)1、数据年份:1961-2022,日数据2、数据范围:中国境内及周边2839个站点的日降

CHM_PRE数据集基于中国境内及周边1961至今共2839个站点的日降水观测,在传统的“降水背景场+ 降水比值场”的数据集构建思路上,尝试应用月值降水约束和地形特征校正,并依据中国范围内约4万个高密度站点2015–2019年的日降水量插值后数据进行精度评价。

yushibing717的博客 2785

DDR5内存命令真值表详解:如何正确解析JESD79-5标准中的关键指令

本文深度解析JESD79-5标准中的DDR5内存命令真值表,将其视为动态通信协议进行拆解。详细阐述了1-Cycle与2-Cycle命令的区别、Bank Group寻址机制以及模式寄存器(MR)操作流程,为硬件与固件工程师提供了从信号解析到系统调试的完整实战指南,是理解和优化高性能计算平台内存子系统的核心。

numpy6sculptor的博客 548

java获取项目所在服务器的ip地址和端口号(获取当前ip地址)

【代码】java获取项目所在服务器的ip地址和端口号(获取当前ip地址)

weixin_45131680的博客 1万+

光模块基础知识【快速入门】02

光模块是用于交换机与设备之间传输的载体,是光纤通信系统中的核心器件。主要作用是发射端将设备的电信号转换成光信号。 光纤通道光模块和以太网光模块 光纤通道光模块 光纤通道(FC, Fiber Channel)是一种高速网络数据传输协议。光纤通道协议可以有序无损地传输原始数据,它主要用于在数据中心、电脑服务器、交换机与存储网络中进行数据传输。 FC光模块遵循FC协议,充当着光纤通道系统之间的接口,也是光纤存储网络设备间的接口。它们主要用于数据中心的光纤通道存储网络链接中。 FC光模块具有小型化和低.

Jin Hanquan的博客 3万+

java获取服务器的ip和地址

写代码的姜总的博客 983

全志A527 T527 android13支持usb摄像头

我们发现usb摄像头在A527 android13上面并不能正常使用,需要支持相关的摄像头。

zhutoubenben的专栏 964

YOLOv11在RK3588芯片上的NPU加速与INT8量化部署全面指南

RK3588 NPU适配YOLOv11的关键技术要点 摘要:本文详细分析了Rockchip RK3588 NPU的硬件架构特性及其对YOLOv11模型的适配优化方案。RK3588 NPU采用三核设计,具备6TOPS算力,包含192个MAC单元和128KB专用SRAM。YOLOv11作为最新目标检测模型,其CSPNet-v5骨干网络、PANet特征金字塔和SiLU激活函数需要特殊适配处理。文章系统介绍了从PyTorch模型导出、ONNX优化到RKNN模型转换的完整流程,重点阐述了NPU不支持的算子处理方案和量

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 1354

Java里面获取当前服务器的IP地址

java中获取当前服务器地址主要使用到InetAddress这个类 public static void main(String[] args) { try { //用 getLocalHost() 方法创建的InetAddress的对象 InetAddress address = InetAddress.getLocalHo...

JavaEE菜鸟 1万+

如何跑通SuperPoint+LightGlue的训练代码使用gluefactory进行训练和评估?

🏆本文收录于专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家!持续更新中,up!up!up!!

**My Coding Family** 1785

java获取服务器ip地址_java中获取当前服务器的Ip地址的方法

1、tomcat是一款免费的开源Web服务器,如果部署在本地,那么对应的那么为localhost,对应地址为127.0.0.1。例子:可以通过http://localhost:8080/项目root值访问,也可以通过http://127.0.0.1/项目root值访问。如果部署在服务器(linux)系统类,则需要通过服务器的Ip地址进行访问。2、下面说说怎么获取Ip地址:获取本地的Ip地址:pub...

weixin_29164185的博客 5115

深度学习工具包 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');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Java-5 获取当前服务器IP地址

获取当前服务器IP地址 import java.net.*; import java.util.*; //获取当前服务器IP public class IPdemo { public static void main(String[] args) { System.out.println(getMyIp()); } @SuppressWarnings(...

梦琪96的博客 1110

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Java获取当前服务器所有的IP地址

Java获取当前服务器所有的IP地址 此代码会列出服务器所有的IP地址,包括IPv4和IPv6的 @Test public void s() throws SocketException { Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();...

qq_43274869的博客 1047

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

java获取当前服务器的IP地址

文章目录1.方法 1.方法 public static void main(String[] args) { String ip=""; InetAddress inetAddress = null; try { Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); whil

qq_42513284的博客 2286

java 取服务器ip_java中获取当前服务器的Ip地址

1、tomcat是一款免费的开源Web服务器,如果部署在本地,那么对应的那么为localhost,对应地址为127.0.0.1。例子:可以通过http://localhost:8080/项目root值访问,也可以通过http://127.0.0.1/项目root值访问。如果部署在服务器(linux)系统类,则需要通过服务器的Ip地址进行访问。2、下面说说怎么获取Ip地址:获取本地的Ip地址:1 p...

weixin_39787057的博客 244
上一篇: mysql服务性能优化—my.cnf_my.ini配置说明详解(服务器16G内存)
下一篇: 手机支付宝,微信的请求userAgent
haohan_lt
博客等级 码龄11年 14粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值