inet address example(socket)
package com.opensource.socket;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
public class InetAddressExample
{
/**
* @param args
*/
public static void main(String[] args)
{
try
{
Enumeration<NetworkInterface> interfaceList = NetworkInterface.getNetworkInterfaces();
if (interfaceList == null)
{
System.out.println("no interfaces found.");
}
else
{
while (interfaceList.hasMoreElements())
{
NetworkInterface iface = interfaceList.nextElement();
System.out.println("Interface:" + iface.getName());
Enumeration<InetAddress> addrList = iface.getInetAddresses();
if (!addrList.hasMoreElements())
{
System.out.println("no address for this interface.");
}
while (addrList.hasMoreElements())
{
InetAddress address = addrList.nextElement();
System.out.print("\tAddress "
+ ((address instanceof Inet4Address ? "(v4)" : (address instanceof Inet6Address ? "(v6)"
: "(?)"))));
System.out.println(": " + address.getHostAddress());
}
}
}
}
catch (SocketException e)
{
System.out.println("SocketException:" + e);
}
for (String host : args)
{
try
{
System.out.println(host + ":");
InetAddress[] addressList = InetAddress.getAllByName(host);
for (InetAddress address : addressList)
{
System.out.println("\t" + address.getHostName() + "/" + address.getHostAddress());
}
}
catch (UnknownHostException e)
{
System.out.println("UnknownHostException:" + e);
}
}
}
}
inet address example(socket)的更多相关文章
- Get the client's IP address in socket.io
From: https://www.wentong.org/codex/question-2018081564702.html When using socket.IO in a Node.js se ...
- Python底层socket库
Python底层socket库将Unix关于网络通信的系统调用对象化处理,是底层函数的高级封装,socket()函数返回一个套接字,它的方法实现了各种套接字系统调用.read与write与Python ...
- Python网络编程(2)——socket模块(2)
目录: 1. 异常 2. 地址族 3. 套接字类型 4. 模块方法 5. Socket对象与实例方法 socket模块提供了Python中的低层网络连接接口,用于操作套接字操作. 异常 socket模 ...
- iOS - Socket 网络套接字
1.Socket 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个 Socket.Socket 又称 "套接字",应用程序通常通过 "套接字& ...
- 【Socket】linux组播技术
1.mystery引入 1)本学期学了计算机网络,对一些网络底层的东西还是不大了解 2)目前IP网络流行3种通信模式,分别是单播/广播与组播 3)根据Internet关于IP地址 ...
- NIO 源码分析(02-2) BIO 源码分析 Socket
目录 一.BIO 最简使用姿势 二.connect 方法 2.1 Socket.connect 方法 2.2 AbstractPlainSocketImpl.connect 方法 2.3 DualSt ...
- 以C语言为例完成简单的网络聊天程序以及关于socket在Linux下系统调用的分析
套接字是网络编程中的一种通信机制,是支持TCP/IP的网络通信的基本操作单元,可以看做是不同主机之间的进程进行双向通信的端点,简单的说就是通信的两方的一种约定,用套接字中的相关函数来完成通信过程. 端 ...
- Socket网络编程一
1.Socket参数介绍 A network socket is an endpoint of a connection across a computer network. Today, most ...
- Python之路,Day8 - Python基础 面向对象高级进阶与socket基础
类的成员 类的成员可以分为三大类:字段.方法和属性 注:所有成员中,只有普通字段的内容保存对象中,即:根据此类创建了多少对象,在内存中就有多少个普通字段.而其他的成员,则都是保存在类中,即:无论对象的 ...
随机推荐
- Oracle Trunc
http://www.cnblogs.com/xiaoyudz/archive/2011/03/18/1988467.html
- 8051_asm.uew
/L20"8051 Assembly" AASM_LANG Line Comment = ; Nocase String Chars = ' File Extensions = S ...
- setAdapter(adapter)空指针nullPointer 解决办法
setAdapter(adapter)空指针nullPointer 解决办法 (2014-06-13 10:01:23) 转载▼ 标签: 旅游 分类: Android开发 如果setAdapter报空 ...
- 大量客户反映wordpress的网站打开巨慢,经分析发现,这些网站大都使用了google的字体服务,由于最近google的服务已经被大陆屏蔽,所以wordpress的网站打开时,会卡在字体加载上。
一会你安装完wp,发现打开巨卡的话,看看这个帖子:http://bbs.myhostcn.com/thread-1026-1-1.html最近一段时间,大量客户反映wordpress的网站打开巨慢, ...
- BFS visit tree
There are two ways to conduct BFS on tree. Solution 1 -- Given level Use recursion to find given lev ...
- OpenWrt backfire trunk源码下载及编译
OpenWrt signature check failed remove wrong signature file svn co svn://svn.openwrt.org/openwrt/bran ...
- ios的一些开源资源
1. http://www.open-open.com/lib/view/open1428646127375.html vim插件:https://github.com/Valloric/YouCom ...
- 本人对于JavaScript的一些总结
类型.值和变量 1.原始类型 数字.字符串和布尔 null空 undefined未定义 2.对象类型 3.类 Array Function Date RegExp Error 4.js ...
- linux内存操作----kernel 3.5.X copy_from_user()和copy_to_user()
前面的一篇文章中简单的描写叙述了一下内存映射的内容,http://blog.csdn.net/codectq/article/details/25658813,这篇文章作为用户把内存规划好之后,在用户 ...
- wso2esb源码编译总结
最近花了两周的空闲时间帮朋友把wso2esb的4.0.3.4.6.0.4.7.0三个版本从源码编译出来了.以下是大概的一些体会. wso2esb是基于carbon的.carbon是个基于eclipse ...