Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.isga.isi.reseaux;
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- public class IPClasses {
- public static String findClass(InetAddress ia) {
- byte[] ip=ia.getAddress();
- String res=null;
- if ((ip[0]& 0x80)==0) res="A";
- if ((ip[0]& 0xC0)==0x80) res="B";
- if ((ip[0]& 0xE0)==0xC0) res="C";
- if ((ip[0]& 0xF0)==0xE0) res="D";
- if ((ip[0]& 0xF0)==0xF0) res="E";
- return res;
- }
- public static String printSquareBrackets(InetAddress ia) {
- byte[] ip=ia.getAddress();
- if(ip.length==4) { //adresse IPv4
- }else { //adresse IPv6
- }
- return null;
- }
- public static void main(String[] args) {
- try {
- InetAddress myLocalHost = InetAddress.getLocalHost();
- System.out.println("My own \"local\" address is : " + myLocalHost);
- String name=null;
- int i;
- for (i = 0; i < args.length; i++) {
- name=args[i];
- InetAddress ia = InetAddress.getByName(name);
- System.out.println("l'adresse "+ia + " est de classe "+findClass(ia));
- }
- } catch (UnknownHostException uhe) {
- System.out.println("Une exception a eu lieu:");
- System.out.println(uhe.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement