网络编程-InetAddress
package cn.hiluna.demo;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 表示互联网中的IP地址
 *      java.net.InetAddress
 *  静态方法
 *      static InetAddress  getLocalHost()  localhost本地主机
 *      返回本地主机,返回值InetAddress对象
 *
 *  static InetAddress getByName(String hostName)  传递一个主机名,获取IP地址对象
 *
 *  非静态方法
 *      String getHostAddress()  获取主机IP地址
 *      String getHostName()  获取主机名字
 */
public class InetAddreddDemo {
    public static void main(String[] args) throws UnknownHostException{
        function();
        function_1();
    }
    public static void function_1()throws UnknownHostException{
        InetAddress inetAddress = InetAddress.getByName("DESKTOP-BVAU4TG");
        System.out.println(inetAddress);
    }
    /**
     * static InetAddress getLocalHost() localhost本地主机
     */
    public static void function() throws UnknownHostException {
        InetAddress inetAddress = InetAddress.getLocalHost();
        //输出结果就是主机名和IP地址
        //System.out.println(inetAddress);
        String ip = inetAddress.getHostAddress();
        String name = inetAddress.getHostName();
        System.out.println(ip+name);
//        String host = inetAddress.toString();
//        String[] strings = host.split("/");
//        for (String s : strings){
//            System.out.println(s);
//        }
    }
}

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇