__init__.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. from ipaddress import IPV4LENGTH, IPV6LENGTH, IPv4Network, ip_address, ip_network
  2. from typing import Dict, List, Optional, Tuple
  3. from text_unidecode import unidecode
  4. from ...utils.decorators import lowercase, slugify, slugify_unicode
  5. from ...utils.distribution import choices_distribution
  6. from .. import BaseProvider, ElementsType
  7. localized = True
  8. class _IPv4Constants:
  9. """
  10. IPv4 network constants used to group networks into different categories.
  11. Structure derived from `ipaddress._IPv4Constants`.
  12. Excluded network list is updated to comply with current IANA list of
  13. private and reserved networks.
  14. """
  15. _network_classes: Dict[str, IPv4Network] = {
  16. "a": ip_network("0.0.0.0/1"),
  17. "b": ip_network("128.0.0.0/2"),
  18. "c": ip_network("192.0.0.0/3"),
  19. }
  20. # Three common private networks from class A, B and CIDR
  21. # to generate private addresses from.
  22. _private_networks: List[IPv4Network] = [
  23. ip_network("10.0.0.0/8"),
  24. ip_network("172.16.0.0/12"),
  25. ip_network("192.168.0.0/16"),
  26. ]
  27. # List of networks from which IP addresses will never be generated,
  28. # includes other private IANA and reserved networks from
  29. # ttps://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
  30. _excluded_networks: List[IPv4Network] = [
  31. ip_network("0.0.0.0/8"),
  32. ip_network("100.64.0.0/10"),
  33. ip_network("127.0.0.0/8"), # loopback network
  34. ip_network("169.254.0.0/16"), # linklocal network
  35. ip_network("192.0.0.0/24"),
  36. ip_network("192.0.2.0/24"),
  37. ip_network("192.31.196.0/24"),
  38. ip_network("192.52.193.0/24"),
  39. ip_network("192.88.99.0/24"),
  40. ip_network("192.175.48.0/24"),
  41. ip_network("198.18.0.0/15"),
  42. ip_network("198.51.100.0/24"),
  43. ip_network("203.0.113.0/24"),
  44. ip_network("224.0.0.0/4"), # multicast network
  45. ip_network("240.0.0.0/4"),
  46. ip_network("255.255.255.255/32"),
  47. ]
  48. class Provider(BaseProvider):
  49. safe_domain_names: ElementsType = ("example.org", "example.com", "example.net")
  50. free_email_domains: ElementsType = ("gmail.com", "yahoo.com", "hotmail.com")
  51. tlds: ElementsType = (
  52. "com",
  53. "com",
  54. "com",
  55. "com",
  56. "com",
  57. "com",
  58. "biz",
  59. "info",
  60. "net",
  61. "org",
  62. )
  63. hostname_prefixes: ElementsType = (
  64. "db",
  65. "srv",
  66. "desktop",
  67. "laptop",
  68. "lt",
  69. "email",
  70. "web",
  71. )
  72. uri_pages: ElementsType = (
  73. "index",
  74. "home",
  75. "search",
  76. "main",
  77. "post",
  78. "homepage",
  79. "category",
  80. "register",
  81. "login",
  82. "faq",
  83. "about",
  84. "terms",
  85. "privacy",
  86. "author",
  87. )
  88. uri_paths: ElementsType = (
  89. "app",
  90. "main",
  91. "wp-content",
  92. "search",
  93. "category",
  94. "tag",
  95. "categories",
  96. "tags",
  97. "blog",
  98. "posts",
  99. "list",
  100. "explore",
  101. )
  102. uri_extensions: ElementsType = (
  103. ".html",
  104. ".html",
  105. ".html",
  106. ".htm",
  107. ".htm",
  108. ".php",
  109. ".php",
  110. ".jsp",
  111. ".asp",
  112. )
  113. http_methods: ElementsType = (
  114. "GET",
  115. "HEAD",
  116. "POST",
  117. "PUT",
  118. "DELETE",
  119. "CONNECT",
  120. "OPTIONS",
  121. "TRACE",
  122. "PATCH",
  123. )
  124. user_name_formats: ElementsType = (
  125. "{{last_name}}.{{first_name}}",
  126. "{{first_name}}.{{last_name}}",
  127. "{{first_name}}##",
  128. "?{{last_name}}",
  129. )
  130. email_formats: ElementsType = (
  131. "{{user_name}}@{{domain_name}}",
  132. "{{user_name}}@{{free_email_domain}}",
  133. )
  134. url_formats: ElementsType = (
  135. "www.{{domain_name}}/",
  136. "{{domain_name}}/",
  137. )
  138. uri_formats: ElementsType = (
  139. "{{url}}",
  140. "{{url}}{{uri_page}}/",
  141. "{{url}}{{uri_page}}{{uri_extension}}",
  142. "{{url}}{{uri_path}}/{{uri_page}}/",
  143. "{{url}}{{uri_path}}/{{uri_page}}{{uri_extension}}",
  144. )
  145. image_placeholder_services: ElementsType = (
  146. "https://www.lorempixel.com/{width}/{height}",
  147. "https://dummyimage.com/{width}x{height}",
  148. "https://placekitten.com/{width}/{height}",
  149. "https://placeimg.com/{width}/{height}/any",
  150. )
  151. replacements: Tuple[Tuple[str, str], ...] = ()
  152. def _to_ascii(self, string: str) -> str:
  153. for search, replace in self.replacements:
  154. string = string.replace(search, replace)
  155. string = unidecode(string)
  156. return string
  157. @lowercase
  158. def email(self, safe: bool = True, domain: Optional[str] = None) -> str:
  159. if domain:
  160. email = f"{self.user_name()}@{domain}"
  161. elif safe:
  162. email = f"{self.user_name()}@{self.safe_domain_name()}"
  163. else:
  164. pattern: str = self.random_element(self.email_formats)
  165. email = "".join(self.generator.parse(pattern).split(" "))
  166. return email
  167. @lowercase
  168. def safe_domain_name(self) -> str:
  169. return self.random_element(self.safe_domain_names)
  170. @lowercase
  171. def safe_email(self) -> str:
  172. return self.user_name() + "@" + self.safe_domain_name()
  173. @lowercase
  174. def free_email(self) -> str:
  175. return self.user_name() + "@" + self.free_email_domain()
  176. @lowercase
  177. def company_email(self) -> str:
  178. return self.user_name() + "@" + self.domain_name()
  179. @lowercase
  180. def free_email_domain(self) -> str:
  181. return self.random_element(self.free_email_domains)
  182. @lowercase
  183. def ascii_email(self) -> str:
  184. pattern: str = self.random_element(self.email_formats)
  185. return self._to_ascii(
  186. "".join(self.generator.parse(pattern).split(" ")),
  187. )
  188. @lowercase
  189. def ascii_safe_email(self) -> str:
  190. return self._to_ascii(self.user_name() + "@" + self.safe_domain_name())
  191. @lowercase
  192. def ascii_free_email(self) -> str:
  193. return self._to_ascii(
  194. self.user_name() + "@" + self.free_email_domain(),
  195. )
  196. @lowercase
  197. def ascii_company_email(self) -> str:
  198. return self._to_ascii(
  199. self.user_name() + "@" + self.domain_name(),
  200. )
  201. @slugify_unicode
  202. def user_name(self) -> str:
  203. pattern: str = self.random_element(self.user_name_formats)
  204. return self._to_ascii(self.bothify(self.generator.parse(pattern)).lower())
  205. @lowercase
  206. def hostname(self, levels: int = 1) -> str:
  207. """
  208. Produce a hostname with specified number of subdomain levels.
  209. >>> hostname()
  210. db-01.nichols-phillips.com
  211. >>> hostname(0)
  212. laptop-56
  213. >>> hostname(2)
  214. web-12.williamson-hopkins.jackson.com
  215. """
  216. hostname_prefix: str = self.random_element(self.hostname_prefixes)
  217. hostname_prefix_first_level: str = hostname_prefix + "-" + self.numerify("##")
  218. return (
  219. hostname_prefix_first_level if levels < 1 else hostname_prefix_first_level + "." + self.domain_name(levels)
  220. )
  221. @lowercase
  222. def domain_name(self, levels: int = 1) -> str:
  223. """
  224. Produce an Internet domain name with the specified number of
  225. subdomain levels.
  226. >>> domain_name()
  227. nichols-phillips.com
  228. >>> domain_name(2)
  229. williamson-hopkins.jackson.com
  230. """
  231. if levels < 1:
  232. raise ValueError("levels must be greater than or equal to 1")
  233. if levels == 1:
  234. return self.domain_word() + "." + self.tld()
  235. return self.domain_word() + "." + self.domain_name(levels - 1)
  236. @lowercase
  237. @slugify_unicode
  238. def domain_word(self) -> str:
  239. company: str = self.generator.format("company")
  240. company_elements: List[str] = company.split(" ")
  241. return self._to_ascii(company_elements.pop(0))
  242. def dga(
  243. self,
  244. year: Optional[int] = None,
  245. month: Optional[int] = None,
  246. day: Optional[int] = None,
  247. tld: Optional[str] = None,
  248. length: Optional[int] = None,
  249. ) -> str:
  250. """Generates a domain name by given date
  251. https://en.wikipedia.org/wiki/Domain_generation_algorithm
  252. :type year: int
  253. :type month: int
  254. :type day: int
  255. :type tld: str
  256. :type length: int
  257. :rtype: str
  258. """
  259. domain = ""
  260. year = year or self.random_int(min=1, max=9999)
  261. month = month or self.random_int(min=1, max=12)
  262. day = day or self.random_int(min=1, max=30)
  263. tld = tld or self.tld()
  264. length = length or self.random_int(min=2, max=63)
  265. for _ in range(length):
  266. year = ((year ^ 8 * year) >> 11) ^ ((year & 0xFFFFFFF0) << 17)
  267. month = ((month ^ 4 * month) >> 25) ^ 16 * (month & 0xFFFFFFF8)
  268. day = ((day ^ (day << 13)) >> 19) ^ ((day & 0xFFFFFFFE) << 12)
  269. domain += chr(((year ^ month ^ day) % 25) + 97)
  270. return domain + "." + tld
  271. def tld(self) -> str:
  272. return self.random_element(self.tlds)
  273. def http_method(self) -> str:
  274. """Returns random HTTP method
  275. https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
  276. :rtype: str
  277. """
  278. return self.random_element(self.http_methods)
  279. def url(self, schemes: Optional[List[str]] = None) -> str:
  280. """
  281. :param schemes: a list of strings to use as schemes, one will chosen randomly.
  282. If None, it will generate http and https urls.
  283. Passing an empty list will result in schemeless url generation like "://domain.com".
  284. :returns: a random url string.
  285. """
  286. if schemes is None:
  287. schemes = ["http", "https"]
  288. pattern: str = f'{self.random_element(schemes) if schemes else ""}://{self.random_element(self.url_formats)}'
  289. return self.generator.parse(pattern)
  290. def _get_all_networks_and_weights(self, address_class: Optional[str] = None) -> Tuple[List[IPv4Network], List[int]]:
  291. """
  292. Produces a 2-tuple of valid IPv4 networks and corresponding relative weights
  293. :param address_class: IPv4 address class (a, b, or c)
  294. """
  295. # If `address_class` has an unexpected value, use the whole IPv4 pool
  296. if address_class in _IPv4Constants._network_classes.keys():
  297. networks_attr = f"_cached_all_class_{address_class}_networks"
  298. all_networks = [_IPv4Constants._network_classes[address_class]] # type: ignore
  299. else:
  300. networks_attr = "_cached_all_networks"
  301. all_networks = [ip_network("0.0.0.0/0")]
  302. # Return cached network and weight data if available
  303. weights_attr = f"{networks_attr}_weights"
  304. if hasattr(self, networks_attr) and hasattr(self, weights_attr):
  305. return getattr(self, networks_attr), getattr(self, weights_attr)
  306. # Otherwise, compute for list of networks (excluding special networks)
  307. all_networks = self._exclude_ipv4_networks(
  308. all_networks,
  309. _IPv4Constants._excluded_networks,
  310. )
  311. # Then compute for list of corresponding relative weights
  312. weights = [network.num_addresses for network in all_networks]
  313. # Then cache and return results
  314. setattr(self, networks_attr, all_networks)
  315. setattr(self, weights_attr, weights)
  316. return all_networks, weights
  317. def _get_private_networks_and_weights(
  318. self,
  319. address_class: Optional[str] = None,
  320. ) -> Tuple[List[IPv4Network], List[int]]:
  321. """
  322. Produces an OrderedDict of valid private IPv4 networks and corresponding relative weights
  323. :param address_class: IPv4 address class (a, b, or c)
  324. """
  325. # If `address_class` has an unexpected value, choose a valid value at random
  326. if not address_class or address_class not in _IPv4Constants._network_classes.keys():
  327. address_class = self.ipv4_network_class()
  328. # Return cached network and weight data if available for a specific address class
  329. networks_attr = f"_cached_private_class_{address_class}_networks"
  330. weights_attr = f"{networks_attr}_weights"
  331. if hasattr(self, networks_attr) and hasattr(self, weights_attr):
  332. return getattr(self, networks_attr), getattr(self, weights_attr)
  333. # Otherwise, compute for list of private networks (excluding special networks)
  334. supernet = _IPv4Constants._network_classes[address_class]
  335. private_networks = [subnet for subnet in _IPv4Constants._private_networks if subnet.overlaps(supernet)]
  336. private_networks = self._exclude_ipv4_networks(
  337. private_networks,
  338. _IPv4Constants._excluded_networks,
  339. )
  340. # Then compute for list of corresponding relative weights
  341. weights = [network.num_addresses for network in private_networks]
  342. # Then cache and return results
  343. setattr(self, networks_attr, private_networks)
  344. setattr(self, weights_attr, weights)
  345. return private_networks, weights
  346. def _get_public_networks_and_weights(
  347. self,
  348. address_class: Optional[str] = None,
  349. ) -> Tuple[List[IPv4Network], List[int]]:
  350. """
  351. Produces a 2-tuple of valid public IPv4 networks and corresponding relative weights
  352. :param address_class: IPv4 address class (a, b, or c)
  353. """
  354. # If `address_class` has an unexpected value, choose a valid value at random
  355. if address_class not in _IPv4Constants._network_classes.keys():
  356. address_class = self.ipv4_network_class()
  357. # Return cached network and weight data if available for a specific address class
  358. networks_attr = f"_cached_public_class_{address_class}_networks"
  359. weights_attr = f"{networks_attr}_weights"
  360. if hasattr(self, networks_attr) and hasattr(self, weights_attr):
  361. return getattr(self, networks_attr), getattr(self, weights_attr)
  362. # Otherwise, compute for list of public networks (excluding private and special networks)
  363. public_networks = [_IPv4Constants._network_classes[address_class]] # type: ignore
  364. public_networks = self._exclude_ipv4_networks(
  365. public_networks,
  366. _IPv4Constants._private_networks + _IPv4Constants._excluded_networks,
  367. )
  368. # Then compute for list of corresponding relative weights
  369. weights = [network.num_addresses for network in public_networks]
  370. # Then cache and return results
  371. setattr(self, networks_attr, public_networks)
  372. setattr(self, weights_attr, weights)
  373. return public_networks, weights
  374. def _random_ipv4_address_from_subnets(
  375. self,
  376. subnets: List[IPv4Network],
  377. weights: Optional[List[int]] = None,
  378. network: bool = False,
  379. ) -> str:
  380. """
  381. Produces a random IPv4 address or network with a valid CIDR
  382. from within the given subnets using a distribution described
  383. by weights.
  384. :param subnets: List of IPv4Networks to choose from within
  385. :param weights: List of weights corresponding to the individual IPv4Networks
  386. :param network: Return a network address, and not an IP address
  387. :return:
  388. """
  389. if not subnets:
  390. raise ValueError("No subnets to choose from")
  391. # If the weights argument has an invalid value, default to equal distribution
  392. if (
  393. isinstance(weights, list)
  394. and len(subnets) == len(weights)
  395. and all(isinstance(w, (float, int)) for w in weights)
  396. ):
  397. subnet = choices_distribution(
  398. subnets,
  399. [float(w) for w in weights],
  400. random=self.generator.random,
  401. length=1,
  402. )[0]
  403. else:
  404. subnet = self.generator.random.choice(subnets)
  405. address = str(
  406. subnet[
  407. self.generator.random.randint(
  408. 0,
  409. subnet.num_addresses - 1,
  410. )
  411. ],
  412. )
  413. if network:
  414. address += "/" + str(
  415. self.generator.random.randint(
  416. subnet.prefixlen,
  417. subnet.max_prefixlen,
  418. )
  419. )
  420. address = str(ip_network(address, strict=False))
  421. return address
  422. def _exclude_ipv4_networks(
  423. self, networks: List[IPv4Network], networks_to_exclude: List[IPv4Network]
  424. ) -> List[IPv4Network]:
  425. """
  426. Exclude the list of networks from another list of networks
  427. and return a flat list of new networks.
  428. :param networks: List of IPv4 networks to exclude from
  429. :param networks_to_exclude: List of IPv4 networks to exclude
  430. :returns: Flat list of IPv4 networks
  431. """
  432. networks_to_exclude.sort(key=lambda x: x.prefixlen)
  433. for network_to_exclude in networks_to_exclude:
  434. def _exclude_ipv4_network(network):
  435. """
  436. Exclude a single network from another single network
  437. and return a list of networks. Network to exclude
  438. comes from the outer scope.
  439. :param network: Network to exclude from
  440. :returns: Flat list of IPv4 networks after exclusion.
  441. If exclude fails because networks do not
  442. overlap, a single element list with the
  443. orignal network is returned. If it overlaps,
  444. even partially, the network is excluded.
  445. """
  446. try:
  447. return list(network.address_exclude(network_to_exclude))
  448. except ValueError:
  449. # If networks overlap partially, `address_exclude`
  450. # will fail, but the network still must not be used
  451. # in generation.
  452. if network.overlaps(network_to_exclude):
  453. return []
  454. else:
  455. return [network]
  456. nested_networks = list(map(_exclude_ipv4_network, networks))
  457. networks = [item for nested in nested_networks for item in nested]
  458. return networks
  459. def ipv4_network_class(self) -> str:
  460. """
  461. Returns a IPv4 network class 'a', 'b' or 'c'.
  462. :returns: IPv4 network class
  463. """
  464. return self.random_element("abc")
  465. def ipv4(
  466. self,
  467. network: bool = False,
  468. address_class: Optional[str] = None,
  469. private: Optional[str] = None,
  470. ) -> str:
  471. """
  472. Returns a random IPv4 address or network with a valid CIDR.
  473. :param network: Network address
  474. :param address_class: IPv4 address class (a, b, or c)
  475. :param private: Public or private
  476. :returns: IPv4
  477. """
  478. if private is True:
  479. return self.ipv4_private(address_class=address_class, network=network)
  480. elif private is False:
  481. return self.ipv4_public(address_class=address_class, network=network)
  482. else:
  483. all_networks, weights = self._get_all_networks_and_weights(address_class=address_class)
  484. return self._random_ipv4_address_from_subnets(all_networks, weights=weights, network=network)
  485. def ipv4_private(self, network: bool = False, address_class: Optional[str] = None) -> str:
  486. """
  487. Returns a private IPv4.
  488. :param network: Network address
  489. :param address_class: IPv4 address class (a, b, or c)
  490. :returns: Private IPv4
  491. """
  492. private_networks, weights = self._get_private_networks_and_weights(address_class=address_class)
  493. return self._random_ipv4_address_from_subnets(private_networks, weights=weights, network=network)
  494. def ipv4_public(self, network: bool = False, address_class: Optional[str] = None) -> str:
  495. """
  496. Returns a public IPv4 excluding private blocks.
  497. :param network: Network address
  498. :param address_class: IPv4 address class (a, b, or c)
  499. :returns: Public IPv4
  500. """
  501. public_networks, weights = self._get_public_networks_and_weights(address_class=address_class)
  502. return self._random_ipv4_address_from_subnets(public_networks, weights=weights, network=network)
  503. def ipv6(self, network: bool = False) -> str:
  504. """Produce a random IPv6 address or network with a valid CIDR"""
  505. address = str(ip_address(self.generator.random.randint(2 ** IPV4LENGTH, (2 ** IPV6LENGTH) - 1)))
  506. if network:
  507. address += "/" + str(self.generator.random.randint(0, IPV6LENGTH))
  508. address = str(ip_network(address, strict=False))
  509. return address
  510. def mac_address(self) -> str:
  511. mac = [self.generator.random.randint(0x00, 0xFF) for _ in range(0, 6)]
  512. return ":".join(map(lambda x: "%02x" % x, mac))
  513. def port_number(self, is_system: bool = False, is_user: bool = False, is_dynamic: bool = False) -> int:
  514. """Returns a network port number
  515. https://tools.ietf.org/html/rfc6335
  516. :param is_system: System or well-known ports
  517. :param is_user: User or registered ports
  518. :param is_dynamic: Dynamic / private / ephemeral ports
  519. :rtype: int
  520. """
  521. if is_system:
  522. return self.random_int(min=0, max=1023)
  523. elif is_user:
  524. return self.random_int(min=1024, max=49151)
  525. elif is_dynamic:
  526. return self.random_int(min=49152, max=65535)
  527. return self.random_int(min=0, max=65535)
  528. def uri_page(self) -> str:
  529. return self.random_element(self.uri_pages)
  530. def uri_path(self, deep: Optional[int] = None) -> str:
  531. deep = deep if deep else self.generator.random.randint(1, 3)
  532. return "/".join(
  533. self.random_elements(self.uri_paths, length=deep),
  534. )
  535. def uri_extension(self) -> str:
  536. return self.random_element(self.uri_extensions)
  537. def uri(self) -> str:
  538. pattern: str = self.random_element(self.uri_formats)
  539. return self.generator.parse(pattern)
  540. @slugify
  541. def slug(self, value: Optional[str] = None) -> str:
  542. """Django algorithm"""
  543. if value is None:
  544. value = self.generator.text(20)
  545. return value
  546. def image_url(self, width: Optional[int] = None, height: Optional[int] = None) -> str:
  547. """
  548. Returns URL to placeholder image
  549. Example: http://placehold.it/640x480
  550. """
  551. width_ = width or self.random_int(max=1024)
  552. height_ = height or self.random_int(max=1024)
  553. placeholder_url: str = self.random_element(self.image_placeholder_services)
  554. return placeholder_url.format(width=width_, height=height_)
  555. def iana_id(self) -> str:
  556. """Returns IANA Registrar ID
  557. https://www.iana.org/assignments/registrar-ids/registrar-ids.xhtml
  558. :rtype: str
  559. """
  560. return str(self.random_int(min=1, max=8888888))
  561. def ripe_id(self) -> str:
  562. """Returns RIPE Organization ID
  563. https://www.ripe.net/manage-ips-and-asns/db/support/organisation-object-in-the-ripe-database
  564. :rtype: str
  565. """
  566. lex = "?" * self.random_int(min=2, max=4)
  567. num = "%" * self.random_int(min=1, max=5)
  568. return self.bothify(f"ORG-{lex}{num}-RIPE").upper()
  569. def nic_handle(self, suffix: str = "FAKE") -> str:
  570. """Returns NIC Handle ID
  571. https://www.apnic.net/manage-ip/using-whois/guide/person/
  572. :rtype: str
  573. """
  574. if len(suffix) < 2:
  575. raise ValueError("suffix length must be greater than or equal to 2")
  576. lex = "?" * self.random_int(min=2, max=4)
  577. num = "%" * self.random_int(min=1, max=5)
  578. return self.bothify(f"{lex}{num}-{suffix}").upper()
  579. def nic_handles(self, count: int = 1, suffix: str = "????") -> List[str]:
  580. """Returns NIC Handle ID list
  581. :rtype: list[str]
  582. """
  583. return [self.nic_handle(suffix=suffix) for _ in range(count)]