List of usage examples for org.apache.commons.net.util SubnetUtils SubnetUtils
public SubnetUtils(String cidrNotation)
From source file:org.sipfoundry.sipxconfig.time.NtpSettings.java
public List<SubnetInfo> getAlowedSubnetInfo() { String allowedNetworks = (String) getSettingTypedValue(ALLOWED_NETWORKS_SETTING); List<SubnetInfo> subnetInfo = new ArrayList<SubnetInfo>(); if (isProvideTimeSettingsEnabled()) { String[] networks = StringUtils.split(allowedNetworks, ","); if (networks != null) { for (String cidNetwork : networks) { try { subnetInfo.add(new SubnetUtils(StringUtils.deleteWhitespace(cidNetwork)).getInfo()); } catch (IllegalArgumentException ex) { continue; }//from ww w. j a v a 2s . c om } } } return subnetInfo; }
From source file:org.springframework.data.hadoop.util.net.DefaultHostInfoDiscovery.java
private boolean matchIpv4(String addressMatch, String address) { // TODO: should we fork utils from jakarta commons? SubnetUtils subnetUtils = new SubnetUtils(addressMatch); SubnetInfo info = subnetUtils.getInfo(); return info.isInRange(address); }
From source file:org.wikimedia.analytics.kraken.pageview.CidrFilter.java
/** * Default constructor that use WMF internal IP ranges */// www .ja v a2 s. c o m public CidrFilter() { /** * 10.x.x.x are internal IP addresses. */ this.subnets.add(new SubnetUtils("10.0.0.0/8")); /** * 208.80.152.0/22 && 91.198.174.0/24 are internal WMF office ranges and should be excluded from * pageview counts */ this.subnets.add(new SubnetUtils("208.80.152.0/22")); this.subnets.add(new SubnetUtils("91.198.174.0/24")); }
From source file:org.wikimedia.analytics.kraken.pageview.CidrFilter.java
/** * * @param subnetInput a comma separated list of subnets using the CIDR notation. *///from ww w .j a va2 s.c o m public CidrFilter(final String subnetInput) { for (String subnet : subnetInput.split(",")) { SubnetUtils subnetUtil = new SubnetUtils(subnet); subnetUtil.setInclusiveHostCount(true); this.subnets.add(subnetUtil); } }
From source file:org.xdi.oxauth.service.external.context.ExternalScriptContext.java
public boolean isInNetwork(String cidrNotation) { final String ip = getIpAddress(); if (Util.allNotBlank(ip, cidrNotation)) { final SubnetUtils utils = new SubnetUtils(cidrNotation); return utils.getInfo().isInRange(ip); }/* w ww. j av a 2s. c o m*/ return false; }
From source file:org.xlcloud.network.validatation.CIDRValidator.java
private static SubnetUtils toSubnetUtils(String cidr) { validateThat(cidr).as("cidr").isNotBlank(); SubnetUtils utils = null;//from w ww . j a va 2s. com try { utils = new SubnetUtils(cidr); } catch (IllegalArgumentException ex) { throw new ValidationException("Invalid CIDR format", ValidationFailureType.CIDR_FORMAT); } int cidrAddress = ipAddressToInt(utils.getInfo().getAddress()); int lowestAddress = ipAddressToInt(utils.getInfo().getLowAddress()); if (cidrAddress > lowestAddress) { throw new ValidationException("Ip address for CIDR has numbers for 0 mask", ValidationFailureType.CIDR_FORMAT); } return utils; }
From source file:OSFFM_ORC.FederationActionManager.java
/** * This function is prepared for future usage it has the scope to add a * network segment inside Openstack in order to absolve at a FEDSDN calls. * * @param fu// ww w.j a v a2 s . co m * @param OSF_network_segment_id * @param OSF_cloud * @param netParameter * @param federationTenant * @return * @throws Exception */ public JSONObject networkSegmentAdd(FederationUser fu, String OSF_network_segment_id, String OSF_cloud, HashMap netParameter, String federationTenant) throws Exception { DBMongo db = new DBMongo(); JSONObject reply = new JSONObject(); db.init(); db.setDbName(federationTenant); db.connectLocale(db.getMdbIp()); HashMap fum = this.getAllFederatedCloudCreds(fu); JSONObject network_info = new JSONObject(), network_infoGLOBAL = new JSONObject(); JSONArray ja = new JSONArray(); Set s = fum.keySet(); OpenstackInfoContainer credential = null; NeutronTest neutron = null; Iterator i = s.iterator(); FederatedUser fed_U = null; while (i.hasNext()) { try { //Momentaneamente viene implementata una gestione singola del cloud federato. //nel caso in cui si decider di gestire globalmente l'insieme dei cloud federati fare come indicato sotto, rimuovendo ////l'if che controlla il cloud //////>>>BEACON: inserire gestione con array di thread ogni thread dovr: JSONObject fdu = (JSONObject) fum.get(i.next()); if (!((String) fdu.get("federatedCloud")).equals(OSF_cloud)) { continue; } fed_U = new FederatedUser(fdu.toString()); String federated_cmp_endp = (String) db .getDatacenterFromId(fu.getUser(), (String) fdu.get("federatedCloud")).get("idmEndpoint");//TO BE VERIFIED credential = new OpenstackInfoContainer((String) fdu.get("federatedCloud"), federated_cmp_endp, fu.getUser(), (String) fdu.get("federatedUser"), (String) fdu.get("federatedPassword"), fed_U.getRegion()); neutron = new NeutronTest(credential.getEndpoint(), credential.getTenant(), credential.getUser(), credential.getPassword(), credential.getRegion()); } catch (Exception e) { reply.put("returncode", 1); reply.put("errormesg", "USER_AUTHENTICATION_EXCEPTION: OPERATION ABORTED"); reply.put("network_info", "null"); LOGGER.error("USER_AUTHENTICATION_EXCEPTION: OPERATION ABORTED >>>[Token:" + fu.getToken() + "]; No federated credential has found for selected parameters."); throw new Exception(reply.toString()); } String cidr = ""; boolean found = false, cidrPresent = false; String internalNetId = db.getInternalNetworkID(fu.getUser(), OSF_network_segment_id, fed_U.getCloud()); if (internalNetId != null) { Networks N = neutron.listNetworks(); Iterator<Network> iN = N.iterator(); found = false; while (i.hasNext() && !found) { Network n = iN.next(); if (internalNetId.equals(n.getId())) { found = true;//nothing to do } } if (!found) { //this is the case when some info aren't aligned, the internal ID for netsegment are present but //// no network is retrieved for tenant inside the cloud match it. //Inserire qui la chiamata relativa al Network Segment verso l'API "/fednet/{fednetId}/{site_id}/netsegment/{netsegment_id}" ////da cui ritrovare tutte le varie //in alternativa creare le informazioni qui: HashMap th = new HashMap(); th.put("netsegments", OSF_network_segment_id); org.json.JSONObject j = db.getcidrInfoes(fu.getUser(), th); if (j != null) { //this is the case when a cidr is already defined for this fednet and FederationUser. That would mean that we have to create the ////other netsegments of the fednet with ther same parameters. th = new HashMap(); th.put("netsegments", OSF_network_segment_id); th.put("cloudId", fed_U.getCloud()); org.json.JSONObject j2 = db.getcidrInfoes(fu.getUser(), th); if (j2 == null) { //on mongo the netsegments searched is not found for this cloud then we will take the federation cidr cidr = (String) j.get("cidr"); } else { //disallineamento presente un cidr ma non c' un internalId che corrisponda al netsegments //sarebbe giusto creare un eccezione throw new Exception( "A problematic situation is founded! MongoDB information aren't alingned Contact the administrator!"); } } else { //this is the case when on mongo the cidr for netsegments indicated is not found. This case represent first istantiation of the ////netsegment for this fednet and FederationUser. cidrPresent = true; } } else { //match //nothing to do } } else { internalNetId = java.util.UUID.randomUUID().toString(); } //prepare and retrieve information for creation of network Boolean dhcp = (Boolean) netParameter.get("dhcpEnable"); if (dhcp == null) { dhcp = false; } Boolean shared = (Boolean) netParameter.get("shared"); if (shared == null) { shared = false; } Boolean external = (Boolean) netParameter.get("external"); if (external == null) { external = false; } Boolean adminStateUp = (Boolean) netParameter.get("adminStateUp"); if (adminStateUp == null) { adminStateUp = false; } String subnetId = java.util.UUID.randomUUID().toString(); if (!cidrPresent) { cidr = this.cidrgen(); } HashMap allpo = this.calculateAllocationPool(cidr); SubnetUtils su = new SubnetUtils(cidr); SubnetInfo si = su.getInfo(); String gwadd = si.getLowAddress(); String fednets = "";//fednet; try { FunctionResponseContainer frc = neutron.createCompleteNetw(fed_U.getRegion(), internalNetId, cidr, (String) allpo.get("allocationPoolStart"), (String) allpo.get("allocationPoolEnd"), subnetId, gwadd, dhcp, fu.getUser(), shared, external, adminStateUp, fednets); //da frc. si possono ottenere le informazioni qui presenti /* Network{id=258453f7-b655-4fbd-bee6-d1ac2d9fe7bc, status=ACTIVE, subnets=[], name=ert, adminStateUp=true, shared=true, tenantId=demo, networkType=null, physicalNetworkName=null, segmentationId=null, external=true, portSecurity=null, profileId=null, multicastIp=null, segmentAdd=null, segmentDel=null, memberSegments=null, segments=null, networkFlavor=null} */ } catch (Exception e) { LOGGER.error("Exception occurred in network creation operation!"); } db.storeInternalNetworkID(fu.getUser(), OSF_network_segment_id, fed_U.getCloud(), internalNetId); db.insertcidrInfoes(fu.getUser(), cidr, fednets, OSF_network_segment_id, fed_U.getCloud()); network_info = new JSONObject(); network_info.put("cloudId", fed_U.getCloud()); network_info.put("internalId", internalNetId); network_info.put("FedSDN_netSegId", OSF_network_segment_id); network_info.put("network_address", cidr.subSequence(0, cidr.indexOf("/"))); network_info.put("network_mask", si.getNetmask()); network_info.put("size", si.getAddressCount()); ja.put(network_info); } network_infoGLOBAL.put("ResponseArray", ja); ///DECIDERE COME GESTIRE LE INFORMAZIONI: COSA RESTITUIRE AL FEDSDN ////momentaneamente viene restituito un JSONarray con un solo elemento, quello della cloud indicata da OSF_cloud reply.put("returncode", 0); reply.put("errormesg", "None"); reply.put("network_info", network_infoGLOBAL); return reply; }
From source file:OSFFM_ORC.FederationActionManager.java
/** * * @param cidr/*from w w w . j a v a2 s . c om*/ * @return * @throws Exception * @author gtricomi */ private HashMap calculateAllocationPool(String cidr) throws Exception { HashMap hm = new HashMap(); String allocationPoolStart = this.nextIpAddress(cidr); //we need the third IP of the allocation pool for (int i = 0; i < 2; i++) { allocationPoolStart = this.nextIpAddress(allocationPoolStart); } hm.put("allocationPoolStart", allocationPoolStart); SubnetUtils su = new SubnetUtils(cidr); SubnetInfo si = su.getInfo(); hm.put("allocationPoolEnd", si.getHighAddress()); return hm; }
From source file:OSFFM_ORC.FederationActionManager.java
/** * * @param mapContainer/* www .ja v a 2 s . com*/ * @param sClient * @param nClient * @param fedsdnURL * @param federationTenant * @param m * @throws WSException * @throws JSONException * @author gtricomi */ private void checkNetSegmentandInsertFEDSDN(FednetsLink mapContainer, Site sClient, NetworkSegment nClient, String fedsdnURL, String federationTenant, DBMongo m) throws WSException, JSONException { Response r = sClient.getAllSite(fedsdnURL); JSONArray ja = new JSONArray(r.readEntity(String.class)); FederationAgentInfo fa = null; for (int i = 0; i < ja.length(); i++) { JSONObject jo = (JSONObject) ja.get(i); String siteNameToCheck = (String) jo.get("name"); Set sstt = mapContainer.getCloudId_To_OIC().keySet(); if (sstt.contains(siteNameToCheck)) { if (mapContainer.getCloudId_To_OIC().get(siteNameToCheck) != null) { fa = mapContainer.getEndpoint_To_FAInfo() .get(mapContainer.getCloudId_To_OIC().get(siteNameToCheck)); NeutronTest neutron = new NeutronTest( mapContainer.getCloudId_To_OIC().get(siteNameToCheck).getEndpoint(), mapContainer.getCloudId_To_OIC().get(siteNameToCheck).getTenant(), mapContainer.getCloudId_To_OIC().get(siteNameToCheck).getUser(), mapContainer.getCloudId_To_OIC().get(siteNameToCheck).getPassword(), mapContainer.getCloudId_To_OIC().get(siteNameToCheck).getRegion()); Networks ns = neutron.listNetworks(); int federationTenantID, siteid, fednetID; Iterator<Network> itNet = ns.iterator(); while (itNet.hasNext()) { Network n = itNet.next(); UnmodifiableIterator<String> ti = n.getSubnets().iterator(); while (ti.hasNext()) { Subnet s = neutron.getSubnet((String) ti.next()); if ((s != null) && (s.getIpVersion() == 4)) {//We want manage only ipv4 network SubnetInfo si = new SubnetUtils(s.getCidr()).getInfo(); boolean ok = false; JSONObject faurl = null; try { siteid = m.getfedsdnSiteID(siteNameToCheck, federationTenant); federationTenantID = new Integer( m.getfedsdnTenantid(federationTenant, federationTenant)); fednetID = m.getfedsdnFednetID(n.getName(), federationTenant); faurl = new JSONObject(m.getFAInfo(federationTenant, siteNameToCheck)); } catch (Exception ex) { LOGGER.error("Retrieving information from Mongo is failed for network: " + n.getName()); break; } for (int k = 0; k < 3; k++) { ok = this.addNetSegOnFedSDN(//attenzione aggungiere anche il fednetID, site ID e referenceSite s.getName(), //m.getInfo_Endpoint("entity", "osffm") + "/fednet/eastBr/network",//sostituire con il FA del sito??SI SOSTITUIRE siteNameToCheck faurl.getString("Ip") + ":" + faurl.getString("Port"), si.getAddress(), si.getNetmask(), si.getAddressCount(), nClient, fedsdnURL, federationTenantID, siteid, m, federationTenant, siteNameToCheck, fednetID); if (ok) { break; } else if (k == 3) { LOGGER.error( "Something going wrong! It's Impossible add Networksegment on FEDSDN"); } } } } //update fednet on Mongo. } } else { int federationTenantID, siteid, fednetID; JSONObject faurl = null; boolean ok = false; try { siteid = m.getfedsdnSiteID(siteNameToCheck, federationTenant); federationTenantID = new Integer(m.getfedsdnTenantid(federationTenant, federationTenant)); fednetID = m.getfedsdnFednetID("reviewPrivate", federationTenant); faurl = new JSONObject(m.getFAInfo(federationTenant, siteNameToCheck)); for (int k = 0; k < 3; k++) { ok = this.addNetSegOnFedSDN(//attenzione aggungiere anche il fednetID, site ID e referenceSite "privatereviewsub", //m.getInfo_Endpoint("entity", "osffm") + "/fednet/eastBr/network",//sostituire con il FA del sito??SI SOSTITUIRE siteNameToCheck faurl.getString("Ip") + ":" + faurl.getString("Port"), "80.0.0.0", "255.255.255.0", 255, nClient, fedsdnURL, federationTenantID, siteid, m, federationTenant, siteNameToCheck, fednetID); if (ok) { break; } else if (k == 3) { LOGGER.error("Something going wrong! It's Impossible add Networksegment on FEDSDN"); } } } catch (Exception ex) { LOGGER.error("Retrieving information from Mongo is failed for network: reviewPrivate"); break; } } } } }
From source file:projetohorus.DadosColetadosPDF.java
void GerarPDF() throws IOException, DocumentException, EmailException { Document doc = null;/*from ww w . j a va 2s. c o m*/ OutputStream os = null; try { doc = new Document(PageSize.A4, 72, 72, 72, 72); os = new FileOutputStream("tesfinal11.pdf"); PdfWriter.getInstance(doc, os); doc.open(); Image img = Image.getInstance("LogoProject.png"); img.setAlignment(Element.ALIGN_CENTER); doc.add(img); InetAddress localHost = Inet4Address.getLocalHost(); NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost); short x = networkInterface.getInterfaceAddresses().get(0).getNetworkPrefixLength(); String n = localHost.getHostAddress() + "/" + x; SubnetUtils utils = new SubnetUtils(n); ; PdfPTable table = new PdfPTable(new float[] { 0.50f, 0.70f, 0.90f }); table = new PdfPTable(3); Paragraph p = new Paragraph(""); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(30); doc.add(p); p = new Paragraph("Informaes da Network"); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(30); doc.add(p); Paragraph paragraph = new Paragraph("" + utils.getInfo()); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(30); doc.add(paragraph); table.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell header = new PdfPCell(new Paragraph("Diagnostico do Scanner da Rede")); header.setColspan(3); table.addCell(header); table.addCell("IP"); table.addCell("HostName"); table.addCell("Portas Abertas"); for (int i = 0; i < IP.size(); i++) { table.addCell(IP.get(i)); table.addCell(NameHost.get(i)); table.addCell("" + PortasA.get(i)); } doc.add(table); } finally { if (doc != null) { doc.close(); } if (os != null) { os.close(); } } EnvioEmail sc = new EnvioEmail(); sc.EnvioEmail(); }