网络编程【一】

[img]
[img]http://dl.iteye.com/upload/attachment/0081/8590/1931be4f-72e5-3617-85a8-1add1b72d533.png[/img]
[/img]


[img]
[img]http://dl.iteye.com/upload/attachment/0081/8592/96fe0081-ca5d-3b3f-af94-d12750ecb3ea.png[/img]
[/img]


[img]
[img]http://dl.iteye.com/upload/attachment/0081/8594/032df6fb-8aee-3b8e-b0ec-c689225074ff.png[/img]
[/img]


[img]
[img]http://dl.iteye.com/upload/attachment/0081/8596/de69b1ee-881f-3293-a64d-12c3c1f1c689.png[/img]
[/img]


package com.zzl.thread;

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


public class NetDemo {

public static void main(String[] args) {


try {
//获取本机的ip地址和计算机名
InetAddress ia = InetAddress.getLocalHost();
String name = ia.getHostName();
String address = ia.getHostAddress();
System.out.println("name==="+name);
System.out.println("address==="+address);
} catch (UnknownHostException e) {
e.printStackTrace();
}

try {
//获取百度的主机地址和主机名
InetAddress ia = InetAddress.getByName("www.baidu.com");
String name = ia.getHostName();
String address = ia.getHostAddress();
System.out.println("百度name=="+name);
System.out.println("百度address=="+address);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}

}

运行结果:
name===admin-PC
address===192.168.0.124
百度name==www.baidu.com
百度address==61.135.169.125
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值