Identification of CIDR blocks of China Mobile Unicom and China Telecom

Source: Internet
Author: User

 

/** Determine which of the following numbers is China Unicom, China Mobile, and China Telecom,
  1. * Before using this method, verify the validity rules of the number:
  2. *
  3. * China Mobile has 16 segments: 139,138,137,136,135,134,147,159,158,157 (3G), 151,152,150,182 (3G), 188 (3G), 187 (3G)
  4. * China Unicom has the following code segments: 130,131,132,145,155,156 (3G), 186 (3G), 185 (3G), and 8 Number segments.
  5. * China Telecom has the following code segments: 133,1349, 153,189 (3G), 180 (3g), and 5
  6. * @ Param Mobile: number to be determined
  7. * @ Return returns the corresponding type: 1 represents China Unicom; 2 represents China Mobile; 3 represents China Telecom.
  8. */
  9. Public String getmobiletype (string mobile ){
  10. If (mobile. startswith ("0") | mobile. startswith ("+ 860 ")){
  11. Mobile = Mobile. substring (mobile. indexof ("0") + 1, mobile. Length ());
  12. }
  13. List chinaunicom = arrays. aslist (New String [] {"130", "131", "132 ",
  14. "145", "155", "156", "186", "185 "});
  15. List chinamobile1 = arrays. aslist (New String [] {"135", "136", "137 ",
  16. "138", "139", "147", "150", "151", "152", "157", "158", "159", "182 ", "187 ",
  17. "188 "});
  18. List chinamobile2 = arrays. aslist (New String [] {"1340", "1341 ",
  19. "1342", "1343", "1344", "1345", "1346", "1347", "1348 "});
  20. Boolean bolchinaunicom = (chinaunicom. Contains (mobile. substring (0, 3 )));
  21. Boolean bolchinamobile1 = (chinamobile1
  22. . Contains (mobile. substring (0, 3 )));
  23. Boolean bolchinamobile2 = (chinamobile2
  24. . Contains (mobile. substring (0, 4 )));
  25. If (bolchinaunicom)
  26. Return "1"; // China Unicom
  27. If (bolchinamobile1 | bolchinamobile2)
  28. Return "2"; // move
  29. Return "3"; // others are Telecom
  30. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.