📄 tp1.java
字号:
/*
* tp&.java
*
* Created on 11 octobre 2008, 12:25
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package reseaux;
/**
*
* @author Mustapha
*/
import java.net.*;
public class tp1 {
/** Creates a new instance of tp1 */
public tp1() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// InetAddress adress = InetAddress.getByName("www.google.com");
try{
//InetAddress adress = InetAddress.getByName("www.google.com");
// InetAddress [] adr = InetAddress.getAllByName("www.google.com");
InetAddress local = InetAddress.getLocalHost();
InetAddress a = InetAddress.getLocalHost(); ;
InetAddress aa = InetAddress.getLocalHost();;
if(a.equals(aa))
{
System.out.println("ok");
}
else
{
System.out.println("non");
}
int b = getversion(local);
char c = getclass(local);
System.out.println(local.getHostAddress()+" IPv "+b+" et de classe "+c);
}
catch(UnknownHostException e)
{
System.out.println("erreur");
}
}
public static int getversion(InetAddress a )
{
byte [] adres = a.getAddress();
if(adres.length==4)
return 4;
else if(adres.length==6) return 6;
else return -1;
}
public static char getclass(InetAddress a )
{
byte [] adres = a.getAddress();
if(adres.length==4)
{
int b1 = adres[0];
if((b1&0x80)==0) return 'A';
else
{
if ((b1&0xc0)==0x80) return 'B';
else
{
if ((b1&0xe0)==0xc0) return 'C';
else
{
if ((b1&0xf0)==0xf0) return 'D';
else
{
if ((b1&0xf8)==0xf0) return 'E';
else return 'X';
}
}
}
}
}
else return 'X';
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -