%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.*,java.util.*"%> <%! String title = "NetCalc"; /* Nota: la funzione calcolaNetmask è fornita agli studenti assieme al testo dell'esame */ protected int[] calcolaNetmask(int n){ int shft = 0xffffffff<<(32-n); int oct1 = ((byte) ((shft&0xff000000)>>24)) & 0xff; int oct2 = ((byte) ((shft&0x00ff0000)>>16)) & 0xff; int oct3 = ((byte) ((shft&0x0000ff00)>>8)) & 0xff; int oct4 = ((byte) (shft&0x000000ff)) & 0xff; int[] netmask = new int[] {oct1,oct2,oct3,oct4}; return netmask; } protected int[] calcolaNetid(int[] ip, int[] netmask){ int[] netid = new int[4]; for (int i=0; i<4; i++) netid[i] = ip[i] & netmask[i]; return(netid);} protected int calcolaNumHost(int n){ if (n<32) return((int)Math.pow(2,32-n)-2); else return 1;} %> <% String url = request.getRequestURL().toString(); String ip = request.getParameter("ip"); String n=request.getParameter("n"); %>
Netmask:
<%= netmask[0]%>.<%= netmask[1]%>.<%= netmask[2]%>.<%= netmask[3]%>
Network:
<%= netid[0]%>.<%= netid[1]%>.<%= netid[2]%>.<%= netid[3]%>/<%=intn%>
Numero di host:
<%= numhost%>