zoukankan      html  css  js  c++  java
  • Java中的IP对象以及本地域名解析

    本地域名解析操作步骤:

    1.打开C:WINDOWSsystem32driversetc目录

    2.找到host文件,用记事本打开

    3.添加“空间IP  域名”

     1 package WebProgramingDemo;
     2 
     3 import java.io.IOException;
     4 import java.net.InetAddress;
     5 
     6 public class IpDemo {
     7 
     8     /**
     9      * @param args
    10      * @throws IOException
    11      */
    12     public static void main(String[] args) throws IOException {
    13 
    14         InetAddress ip = InetAddress.getByName("www.sina.com.cn");
    15         // 实现原理:调用了getAllByName(host)方法
    16         /*
    17          * public static InetAddress getByName(String host) throws
    18          * UnknownHostException { return InetAddress.getAllByName(host)[0]; }
    19          */
    20         // 返回 IP 地址字符串(以文本表现形式)。
    21         System.out.println("addr:" + ip.getHostAddress());
    22         // 获取此 IP 地址的主机名。
    23         System.out.println("name:" + ip.getHostName());
    24         // 本地域名解析:
    25         // C:WindowsSystem32driversetchosts文件存放的就是本地域名解析文件
    26         // 配置该文件的内容,可以实现屏蔽某些网站的功能,360网站屏蔽网站的原理也是这样,
    27         // 它将这些网站对应的本地域名解析配置成:127.0.0.1
    28     }
    29 
    30 }
  • 相关阅读:
    摩根斯坦利面试
    Interview Preparation IV
    Interview Preparation III
    Interview Preparation II
    Interview Preparation I
    ASCII Characters
    Java Serialization
    贝莱德伦敦分部面试
    SVG基本知识
    前端知识整理(四)【HTTP相关】
  • 原文地址:https://www.cnblogs.com/ysw-go/p/5320164.html
Copyright © 2011-2022 走看看