Exemplo n.º 1
0
 public Entry findDestinationIP(IPAddress ip) {
   if (table.containsKey(ip.toString())) {
     return table.get(ip.toString());
   } else {
     return new Entry("0.0.0.0", "0.0.0.0", 0);
   }
 }
Exemplo n.º 2
0
 @Test
 public void testFromStringValid() {
   ipAddress.fromString("1.2.3.4");
   ipAddress.fromString("255.255.255.255");
   ipAddress.fromString("2001:cdba:0000:0000:0000:0000:3257:9652");
   ipAddress.fromString("2001:cdba:0:0:0:0:3257:9652");
   ipAddress.fromString("2001:cdba::3257:9652");
 }
Exemplo n.º 3
0
  /**
   * Check if the specified IP address is in the encapsulated range.
   *
   * @param address The IP address to be tested.
   * @return Return <code>true</code> if the specified IP address is in the encapsulated IP range,
   *     otherwise return <code>false</code>.
   */
  public boolean isIPAddressInRange(IPAddress address) {
    if (ipSubnetMask == null) {
      return this.ipAddress.equals(address);
    }

    int result1 = address.getIPAddress() & ipSubnetMask.getIPAddress();
    int result2 = ipAddress.getIPAddress() & ipSubnetMask.getIPAddress();

    return result1 == result2;
  }
Exemplo n.º 4
0
  /**
   * Compute the extended network prefix from the IP subnet mask.
   *
   * @param mask Reference to the subnet mask IP number.
   * @return Return the extended network prefix. Return -1 if the specified mask cannot be converted
   *     into a extended prefix network.
   */
  private int computeNetworkPrefixFromMask(IPAddress mask) {

    int result = 0;
    int tmp = mask.getIPAddress();

    while ((tmp & 0x00000001) == 0x00000001) {
      result++;
      tmp = tmp >>> 1;
    }

    if (tmp != 0) {
      return -1;
    }

    return result;
  }
Exemplo n.º 5
0
 public static void method6185(Object object, int i) {
   try {
     if (null != Class403.anEventQueue5262) {
       for (int i_17_ = 0; (i_17_ < 50 && Class403.anEventQueue5262.peekEvent() != null); i_17_++)
         IPAddress.method6060(1L);
       try {
         if (object != null)
           Class403.anEventQueue5262.postEvent(new ActionEvent(object, 1001, "dummy"));
       } catch (Exception exception) {
         /* empty */
       }
     }
   } catch (RuntimeException runtimeexception) {
     throw Class346.method4175(
         runtimeexception, new StringBuilder().append("ug.c(").append(')').toString());
   }
 }
Exemplo n.º 6
0
 /**
  * Resets all <strong>non-identity</strong>fields to null. Fields that are themselves topology
  * objects are not null'ed out, but do have their resetNonIdentity() methods called.
  */
 @Override
 public void reset() {
   if (_resetting == true) {
     return;
   }
   _resetting = true;
   super.reset();
   if (!(_ipAddress == null)) {
     _ipAddress.reset();
   }
   _macAddress = null;
   _interfaceIndex = null;
   _portNumber = null;
   _interfaceType = null;
   _netmask = null;
   _isLayer2 = null;
   _networkSegment = null;
   _layer2Segment = null;
   _discoveryStatus = null;
   if (!(_networks == null)) {
     for (TopologyObject list_element : _networks) {
       list_element.reset();
     }
   }
   _bandwidth = null;
   _utilization = null;
   _packetsSent = null;
   _packetsReceived = null;
   _sendRate = null;
   _receiveRate = null;
   _inboundPacketsDropped = null;
   _outboundPacketsDropped = null;
   _inboundErrors = null;
   _outboundErrors = null;
   _outputQueueLength = null;
   _resetting = false;
 }
Exemplo n.º 7
0
 /**
  * Adds the relevant portions of this topology sample using the provided node.
  *
  * @param submitted Set of objects that have already been submitted
  * @param currentNode This node currently being submitted
  * @param unitService An instance of the unit service for converting units.
  * @throws TopologyException If there are any problems submitting the data for this class.
  */
 @Override
 protected void addPropertiesToNodeTree(
     TopologyNode currentNode, UnitService unitService, Set<UUID> submitted)
     throws TopologyException {
   super.addPropertiesToNodeTree(currentNode, unitService, submitted);
   if (!(_name == null)) {
     final TopologyValue _value104 = currentNode.createValue("name");
     _value104.setSampleValue(_name.toString());
     if (__isIdentity("name")) {
       _value104.setIsIdentity(true);
     }
   }
   if (!(_ipAddress == null)) {
     final TopologyNode _node105 = currentNode.createNode("ipAddress");
     if (__isIdentity("ipAddress")) {
       _node105.setIsIdentity(true);
     }
     if (submitted.contains(_ipAddress.__getNodeId())) {
       // field already submitted, just set the reference ID
       _node105.setRefId(_ipAddress.__getNodeId().toString());
     } else {
       // Not already submitted, send the entire thing
       _node105.setTypeHint(_ipAddress.__getNodeName());
       _node105.setId(_ipAddress.__getNodeId().toString());
       _ipAddress.addToNodeTree(_node105, unitService, submitted);
     }
   }
   if (!(_macAddress == null)) {
     final TopologyValue _value106 = currentNode.createValue("macAddress");
     _value106.setSampleValue(_macAddress.toString());
     if (__isIdentity("macAddress")) {
       _value106.setIsIdentity(true);
     }
   }
   if (!(_interfaceIndex == null)) {
     final TopologyValue _value107 = currentNode.createValue("interfaceIndex");
     _value107.setSampleValue(_interfaceIndex);
     if (__isIdentity("interfaceIndex")) {
       _value107.setIsIdentity(true);
     }
   }
   if (!(_portNumber == null)) {
     final TopologyValue _value108 = currentNode.createValue("portNumber");
     _value108.setSampleValue(_portNumber);
     if (__isIdentity("portNumber")) {
       _value108.setIsIdentity(true);
     }
   }
   if (!(_interfaceType == null)) {
     final TopologyValue _value109 = currentNode.createValue("interfaceType");
     _value109.setSampleValue(_interfaceType.toString());
     if (__isIdentity("interfaceType")) {
       _value109.setIsIdentity(true);
     }
   }
   if (!(_netmask == null)) {
     final TopologyValue _value110 = currentNode.createValue("netmask");
     _value110.setSampleValue(_netmask.toString());
     if (__isIdentity("netmask")) {
       _value110.setIsIdentity(true);
     }
   }
   if (!(_isLayer2 == null)) {
     final TopologyValue _value111 = currentNode.createValue("isLayer2");
     _value111.setSampleValue(_isLayer2.toString());
     if (__isIdentity("isLayer2")) {
       _value111.setIsIdentity(true);
     }
   }
   if (!(_networkSegment == null)) {
     final TopologyValue _value112 = currentNode.createValue("networkSegment");
     _value112.setSampleValue(_networkSegment.toString());
     if (__isIdentity("networkSegment")) {
       _value112.setIsIdentity(true);
     }
   }
   if (!(_layer2Segment == null)) {
     final TopologyValue _value113 = currentNode.createValue("layer2Segment");
     _value113.setSampleValue(_layer2Segment);
     if (__isIdentity("layer2Segment")) {
       _value113.setIsIdentity(true);
     }
   }
   if (!(_discoveryStatus == null)) {
     final TopologyValue _value114 = currentNode.createValue("discoveryStatus");
     _value114.setSampleValue(_discoveryStatus.getValue());
     if (__isIdentity("discoveryStatus")) {
       _value114.setIsIdentity(true);
     }
   }
   if (!(_networks == null)) {
     for (TopologyObject list_element : _networks) {
       final TopologyNode _node115 = currentNode.createNode("networks");
       if (__isIdentity("networks")) {
         _node115.setIsIdentity(true);
       }
       if (_replace_networks) {
         _node115.setReplace(true);
       }
       _replace_networks = false;
       if (submitted.contains(list_element.__getNodeId())) {
         // field already submitted, just set the reference ID
         _node115.setRefId(list_element.__getNodeId().toString());
       } else {
         // Not already submitted, send the entire thing
         _node115.setTypeHint(list_element.__getNodeName());
         _node115.setId(list_element.__getNodeId().toString());
         list_element.addToNodeTree(_node115, unitService, submitted);
       }
     }
   }
   if (!(_bandwidth == null)) {
     final TopologyNode _node116 = currentNode.createNode("bandwidth");
     _bandwidth.submit(_node116, unitService.getUnits("bit/second"));
   }
   if (!(_utilization == null)) {
     final TopologyNode _node117 = currentNode.createNode("utilization");
     _utilization.submit(_node117, unitService.getUnits("percent"));
   }
   if (!(_packetsSent == null)) {
     final TopologyNode _node118 = currentNode.createNode("packetsSent");
     _packetsSent.submit(_node118, unitService.getUnits("count/second"));
   }
   if (!(_packetsReceived == null)) {
     final TopologyNode _node119 = currentNode.createNode("packetsReceived");
     _packetsReceived.submit(_node119, unitService.getUnits("count/second"));
   }
   if (!(_sendRate == null)) {
     final TopologyNode _node120 = currentNode.createNode("sendRate");
     _sendRate.submit(_node120, unitService.getUnits("bit/second"));
   }
   if (!(_receiveRate == null)) {
     final TopologyNode _node121 = currentNode.createNode("receiveRate");
     _receiveRate.submit(_node121, unitService.getUnits("bit/second"));
   }
   if (!(_inboundPacketsDropped == null)) {
     final TopologyNode _node122 = currentNode.createNode("inboundPacketsDropped");
     _inboundPacketsDropped.submit(_node122, unitService.getUnits("count"));
   }
   if (!(_outboundPacketsDropped == null)) {
     final TopologyNode _node123 = currentNode.createNode("outboundPacketsDropped");
     _outboundPacketsDropped.submit(_node123, unitService.getUnits("count"));
   }
   if (!(_inboundErrors == null)) {
     final TopologyNode _node124 = currentNode.createNode("inboundErrors");
     _inboundErrors.submit(_node124, unitService.getUnits("count"));
   }
   if (!(_outboundErrors == null)) {
     final TopologyNode _node125 = currentNode.createNode("outboundErrors");
     _outboundErrors.submit(_node125, unitService.getUnits("count"));
   }
   if (!(_outputQueueLength == null)) {
     final TopologyNode _node126 = currentNode.createNode("outputQueueLength");
     _outputQueueLength.submit(_node126, unitService.getUnits("count"));
   }
 }
Exemplo n.º 8
0
 @Test(expected = java.lang.IllegalArgumentException.class)
 public void testFromStringInvalidFormat() {
   ipAddress.fromString("1234");
 }
Exemplo n.º 9
0
 @Test
 public void testAsInetAddress() {
   IPAddress a1 = ipAddress.fromString("1.2.3.4");
   Assert.assertEquals("1.2.3.4", a1.asInetAddress().getHostAddress());
   IPAddress a2 = ipAddress.fromString("255.255.255.255");
   Assert.assertEquals("255.255.255.255", a2.asInetAddress().getHostAddress());
   IPAddress a3 = ipAddress.fromString("2001:cdba:0000:0000:0000:0000:3257:9652");
   Assert.assertEquals("2001:cdba:0:0:0:0:3257:9652", a3.asInetAddress().getHostAddress());
   IPAddress a4 = ipAddress.fromString("2001:cdba:0:0:0:0:3257:9652");
   Assert.assertEquals("2001:cdba:0:0:0:0:3257:9652", a4.asInetAddress().getHostAddress());
   IPAddress a5 = ipAddress.fromString("2001:cdba::3257:9652");
   Assert.assertEquals("2001:cdba:0:0:0:0:3257:9652", a5.asInetAddress().getHostAddress());
 }
Exemplo n.º 10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    CoreFacade.getInstance().setContext(this.getApplicationContext());

    Intent intent = getIntent();

    if (intent.getExtras() == null) {
      // SLEEP 2 SECONDS HERE ...
      iv = (ImageView) findViewById(R.id.mainImageView);
      iv.setScaleType(ScaleType.FIT_XY);
      iv.setImageResource(R.drawable.main);

      Handler handler = new Handler();
      handler.postDelayed(
          new Runnable() {
            public void run() {

              User user = CoreFacade.getInstance().getCurrentUser();
              if (user == null) {
                Intent intent = new Intent(getApplicationContext(), MyProfile.class);
                startActivity(intent);

              } else {
                Intent listUser = new Intent(getApplicationContext(), Demo.class);
                listUser.putExtra("userName", user.getName());
                listUser.putExtra("latitude", "" + user.getLatitude());
                listUser.putExtra("longitude", "" + user.getLongtitude());
                listUser.putExtra("userName", user.getName());
                listUser.putExtra("pic", user.getPic());
                String ipAdd;
                try {
                  ipAdd = IPAddress.getIPAddress(true);

                  listUser.putExtra("IP", ipAdd);
                  if (user.getSex() == Sex.Female) listUser.putExtra("sex", "Female");
                  else listUser.putExtra("sex", "Male");
                  listUser.putExtra("interests", user.getInterests());
                } catch (IOException e) {
                  e.printStackTrace();
                }
                startActivity(listUser);
              }
            }
          },
          2000);
    } else {
      User user = CoreFacade.getInstance().getCurrentUser();
      if (user == null) {
        Intent intent1 = new Intent(this, MyProfile.class);
        startActivity(intent1);

      } else {
        Intent listUser = new Intent(this, Demo.class);
        listUser.putExtra("userName", user.getName());
        listUser.putExtra("latitude", "" + user.getLatitude());
        listUser.putExtra("longitude", "" + user.getLongtitude());
        listUser.putExtra("userName", user.getName());
        listUser.putExtra("pic", user.getPic());
        String ipAdd;
        try {
          ipAdd = IPAddress.getIPAddress(true);

          listUser.putExtra("IP", ipAdd);
          if (user.getSex() == Sex.Female) listUser.putExtra("sex", "Female");
          else listUser.putExtra("sex", "Male");
          listUser.putExtra("interests", user.getInterests());
        } catch (IOException e) {
          e.printStackTrace();
        }
        startActivity(listUser);
      }
    }
  }
Exemplo n.º 11
0
 /**
  * Convert the IP Range into a string representation.
  *
  * @return Return the string representation of the IP Address following the common format
  *     xxx.xxx.xxx.xxx/xx (IP address/extended network prefixs).
  */
 public String toString() {
   return ipAddress.toString() + "/" + extendedNetworkPrefix;
 }
Exemplo n.º 12
0
 /**
  * 爬取入口,按产品号遍历下载产品页面
  *
  * @param sourceDir 源文件夹
  * @param proNum 产品数量
  * @param beginProId 开始产品号
  * @throws ClientProtocolException
  * @throws URISyntaxException
  * @throws IOException
  */
 public static void crawlZOL(String sourceDir, int proNum, int beginProId)
     throws ClientProtocolException, URISyntaxException, IOException {
   int proId = beginProId;
   int iIP = 0;
   IPAddress ip;
   String today = DateFormater.getDateofToday();
   String sourcePath = sourceDir + "/" + today;
   new File(sourcePath).mkdirs();
   String html;
   ip = IPs.get(iIP);
   String hostName = ip.getHost();
   int port = ip.getPort();
   for (int j = 0; j < proNum; j++) {
     StringBuilder sb = new StringBuilder();
     boolean validPage = false;
     int page = 1;
     while (true) {
       String requestURL =
           "http://detail.zol.com.cn/xhr3_Review_GetListAndPage_order=1%5EisFilter=1%5EproId="
               + proId
               + "%5Epage="
               + page
               + ".html";
       html = HTTPHandler.getHTML(requestURL, hostName, port);
       int iReconn = 0;
       while (html.equals("null")) {
         html = HTTPHandler.getHTML(requestURL, hostName, port);
         iReconn++;
         System.out.println("****" + ip.toString() + " reconnected " + iReconn + " time(s)****");
         if (iReconn == 4) { // 4
           break;
         }
       }
       if (html.equals("null")) {
         System.out.println("****5 consecutive connections were failed, now using next IP****");
         if (iIP == IPNum - 1) {
           System.out.println(
               "****All valid proxy IPs have been tried, still can not get all the data. Now trying the valid proxy IP list again.****");
           iIP = 0;
           System.out.println("****Turn to" + IPs.get(iIP) + ", start connecting****");
         } else {
           iIP++;
           System.out.println("****Turn to" + IPs.get(iIP) + ", start connecting****");
         }
       }
       if (html.length() > 4700) {
         System.out.println(
             "ok!parsing id:" + proId + "\t page : " + page + "\t length:" + html.length());
         sb.append(html + "\n");
         validPage = true;
         page++;
       } else {
         break;
       }
     }
     if (validPage) {
       FileOperation.writeString(
           sb.toString(), sourcePath + "/" + String.valueOf(proId) + ".html");
     }
     proId++;
   }
 }