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)的更多相关文章

  1. 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 ...

  2. Python底层socket库

    Python底层socket库将Unix关于网络通信的系统调用对象化处理,是底层函数的高级封装,socket()函数返回一个套接字,它的方法实现了各种套接字系统调用.read与write与Python ...

  3. Python网络编程(2)——socket模块(2)

    目录: 1. 异常 2. 地址族 3. 套接字类型 4. 模块方法 5. Socket对象与实例方法 socket模块提供了Python中的低层网络连接接口,用于操作套接字操作. 异常 socket模 ...

  4. iOS - Socket 网络套接字

    1.Socket 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个 Socket.Socket 又称 "套接字",应用程序通常通过 "套接字& ...

  5. 【Socket】linux组播技术

    1.mystery引入      1)本学期学了计算机网络,对一些网络底层的东西还是不大了解    2)目前IP网络流行3种通信模式,分别是单播/广播与组播    3)根据Internet关于IP地址 ...

  6. NIO 源码分析(02-2) BIO 源码分析 Socket

    目录 一.BIO 最简使用姿势 二.connect 方法 2.1 Socket.connect 方法 2.2 AbstractPlainSocketImpl.connect 方法 2.3 DualSt ...

  7. 以C语言为例完成简单的网络聊天程序以及关于socket在Linux下系统调用的分析

    套接字是网络编程中的一种通信机制,是支持TCP/IP的网络通信的基本操作单元,可以看做是不同主机之间的进程进行双向通信的端点,简单的说就是通信的两方的一种约定,用套接字中的相关函数来完成通信过程. 端 ...

  8. Socket网络编程一

    1.Socket参数介绍 A network socket is an endpoint of a connection across a computer network. Today, most ...

  9. Python之路,Day8 - Python基础 面向对象高级进阶与socket基础

    类的成员 类的成员可以分为三大类:字段.方法和属性 注:所有成员中,只有普通字段的内容保存对象中,即:根据此类创建了多少对象,在内存中就有多少个普通字段.而其他的成员,则都是保存在类中,即:无论对象的 ...

随机推荐

  1. C# Process类_进程_应用程序域与上下文之间的关系

    进程(Process)是Windows系统中的一个基本概念,它包含着一个运行程序所需要的资源.进程之间是相对独立的,一个进程无法直接访问另一个进程的数据(除非分布式),一个进程运行的失败也不会影响其他 ...

  2. C语言中typedef

    一.基本概念剖析 ])(int, char*); //#1 ]) (void (*)()); //#2 ]; //#3 .C语言中函数声明和数组声明.函数声明一般是这样: int fun(int, d ...

  3. Android Animations 视图动画使用详解!!!

    转自:http://www.open-open.com/lib/view/open1335777066015.html Android Animations 视图动画使用详解 一.动画类型 Andro ...

  4. LED音乐频谱之输出数据处理

    转载请注明出处:http://blog.csdn.net/ruoyunliufeng/article/details/38023539 一.PWM调节 1.初始化 void DACInit() { C ...

  5. C#.NET学习笔记11,12---布尔表达式2组合,if语句

    C#.NET学习笔记11---布尔表达式2组合 2013/9/6 技术qq交流群:JavaDream:251572072  教程下载,在线交流:创梦IT社区:www.credream.com int ...

  6. [Python笔记][第一章Python基础]

    2016/1/27学习内容 第一章 Python基础 Python内置函数 见Python内置函数.md del命令 显式删除操作,列表中也可以使用. 基本输入输出 input() 读入进来永远是字符 ...

  7. linux 能访问内网,但不能访问外网?解决方案

    用iptables就可以了 iptables -F iptables -t nat -F iptables -A INPUT -s -d -j ACCEPT iptables -A INPUT -d ...

  8. Windows下配置sphinx+reStructuredText详解

    最近有朋友想在windows下做个人笔记,没有找到顺手的工具,问我有什么好的工具推荐.正好前两天在网上看到一款做文档的利器sphinx+reStructText,当时在ubuntu下搭了下环境试了试, ...

  9. php中的short_open_tag的作用

    在php的配置文件(php.ini)中有一个short_open_tag的值,开启以后可以使用PHP的段标签:(<? ?>). 同时,只有开启这个才可以使用 <?= 以代替 < ...

  10. 解决 Visual Studio 2012 有时不能调试的问题

    有时候发现 Visual Studio 2012 不能调试,有时候又能调试.感觉很烦,今天找到了一个解决办法,我也不知道为什么这样能解决. 问题: 解决:1. 找到 Properties ,双击 2. ...