portune 0.1.19__py3-none-any.whl → 0.1.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of portune might be problematic. Click here for more details.

portune/portune.py CHANGED
@@ -729,6 +729,24 @@ def ping_host(ip: str, timeout: int = 2) -> bool:
729
729
  except Exception:
730
730
  return False
731
731
 
732
+ def is_ip(hostname: str) -> bool:
733
+ """Check if a given hostname is an IP address.
734
+
735
+ Uses inet_aton to determine if the input string is a valid
736
+ IPv4 address.
737
+
738
+ Args:
739
+ hostname: The hostname or IP address to check
740
+
741
+ Returns:
742
+ True if the hostname is an IP address, False otherwise
743
+ """
744
+ try:
745
+ socket.inet_aton(hostname)
746
+ return True
747
+ except socket.error:
748
+ return False
749
+
732
750
  def resolve_and_ping_host(hostname: str, timeout: int = 2, noping: bool = False) -> Tuple[str, Dict[str, Union[str, bool]]]:
733
751
  """Resolve a hostname to IP and optionally check if it responds to ping.
734
752
 
@@ -749,25 +767,17 @@ def resolve_and_ping_host(hostname: str, timeout: int = 2, noping: bool = False)
749
767
  - 'hostname': Original resolved hostname (only if different from input)
750
768
  """
751
769
  try:
752
- # Check if hostname is already an IP address
753
- try:
754
- # Try to create an IP address object to validate format
755
- socket.inet_aton(hostname)
756
- is_ip = True
757
- except socket.error:
758
- is_ip = False
759
-
760
770
  # If it's an IP, try to get hostname from reverse DNS
761
- if is_ip:
771
+ if is_ip(hostname):
762
772
  try:
763
- resolved_hosts = socket.gethostbyaddr(hostname)
773
+ ip = hostname
774
+ resolved_hosts = socket.gethostbyaddr(ip)
764
775
  if resolved_hosts and resolved_hosts[0]:
765
776
  hostname = resolved_hosts[0] # Use the resolved hostname
766
777
  except (socket.herror, socket.gaierror):
767
778
  pass # Keep the IP as hostname if reverse lookup fails
768
-
769
- # Now resolve the hostname (or IP) to get its IP
770
- ip = socket.gethostbyname(hostname)
779
+ else:
780
+ ip = socket.gethostbyname(hostname)
771
781
  if noping:
772
782
  return hostname, {'ip': ip, 'ping': False}
773
783
  ping_status = ping_host(ip, timeout)
@@ -1101,12 +1111,10 @@ def compute_stats(
1101
1111
  })
1102
1112
 
1103
1113
  for hostname, ip, port, status, _, _ in results:
1104
- # For IP addresses, use VLAN/16 as domain
1105
- try:
1106
- socket.inet_aton(hostname)
1107
- # It's a valid IP address, use VLAN/16
1114
+ if is_ip(hostname):
1115
+ # For IP addresses, use VLAN/16 as domain
1108
1116
  domain = '.'.join(hostname.split('.')[:2]) + '.0.0'
1109
- except socket.error:
1117
+ else:
1110
1118
  # Not an IP address, extract domain normally
1111
1119
  parts = hostname.split('.')
1112
1120
  if len(parts) > 1:
@@ -1410,6 +1418,7 @@ def print_statistics(stats, timeout, parallelism):
1410
1418
  first_row = False
1411
1419
  if not first_row: # Only print separator between domains if domain had data
1412
1420
  print(separator, file=sys.stderr)
1421
+
1413
1422
  def format_table_output(
1414
1423
  results: List[Tuple[str, str, int, str, bool]],
1415
1424
  noping: bool
portune/version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.1.19'
21
- __version_tuple__ = version_tuple = (0, 1, 19)
20
+ __version__ = version = '0.1.20'
21
+ __version_tuple__ = version_tuple = (0, 1, 20)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: portune
3
- Version: 0.1.19
3
+ Version: 0.1.20
4
4
  Summary: Simple Python HTTP Exec Server
5
5
  Author: Franck Jouvanceau
6
6
  Maintainer: Franck Jouvanceau
@@ -36,7 +36,7 @@ Dynamic: license-file
36
36
  [![Licence](https://img.shields.io/badge/licence-MIT-blue.svg)](https://shields.io/)
37
37
  [![](https://pepy.tech/badge/portune)](https://pepy.tech/project/portune)
38
38
  [![Python versions](https://img.shields.io/badge/python-3.9+-blue.svg)](https://shields.io/)
39
- [![bash](https://img.shields.io/badge/OS-Windows%20|Linux%20|%20macOS%20|%20SunOS%20|%20AIX%20|%20HP_UX%20...-blue.svg)]()
39
+ [![bash](https://img.shields.io/badge/OS-%20Windows%20|%20Linux%20|%20macOS%20|%20SunOS%20|%20AIX%20|%20HP_UX%20...-blue.svg)]()
40
40
 
41
41
  # portune
42
42
 
@@ -0,0 +1,9 @@
1
+ portune/__init__.py,sha256=RfXuNfHBqfRt_z4IukwN1a0oeCXahuMOO8_eBt4T8NM,58
2
+ portune/portune.py,sha256=GwTb4SmxdVvLvMqAHdBmbZUDiWcWT9k0rxsXG-n0VsU,67776
3
+ portune/version.py,sha256=HrX7HW5_qgG2kKtggMCOAOnIAM_IUpfjsr4EaS77COI,513
4
+ portune-0.1.20.dist-info/licenses/LICENSE,sha256=gRJf0JPT_wsZJsUGlWPTS8Vypfl9vQ1qjp6sNbKykuA,1064
5
+ portune-0.1.20.dist-info/METADATA,sha256=Yij34H8N8a-HCt08tzcaoofm5wcXe3HVQyaFh7XneDA,2378
6
+ portune-0.1.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ portune-0.1.20.dist-info/entry_points.txt,sha256=6j7jAf5fOZrLPbVIs3z92R1tT891WyY9YxQ6OVnPKG0,80
8
+ portune-0.1.20.dist-info/top_level.txt,sha256=CITDikHhRKAsSOGmNJzD-xSp6D5iBhSr9ZS1qy8-SL0,8
9
+ portune-0.1.20.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- portune/__init__.py,sha256=RfXuNfHBqfRt_z4IukwN1a0oeCXahuMOO8_eBt4T8NM,58
2
- portune/portune.py,sha256=2gx3Xvt9sPjK_JQZgelzhbt8ax6WQfXxsOuj1OtTZRc,67693
3
- portune/version.py,sha256=-W-i-_6L24OJ73VmeltYID1xpUrwRUNYxZXkfU86ff0,513
4
- portune-0.1.19.dist-info/licenses/LICENSE,sha256=gRJf0JPT_wsZJsUGlWPTS8Vypfl9vQ1qjp6sNbKykuA,1064
5
- portune-0.1.19.dist-info/METADATA,sha256=My1iWiWBrwLO2w7mM0Udei24zKwAaDuC_tNOoUje_B4,2372
6
- portune-0.1.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- portune-0.1.19.dist-info/entry_points.txt,sha256=6j7jAf5fOZrLPbVIs3z92R1tT891WyY9YxQ6OVnPKG0,80
8
- portune-0.1.19.dist-info/top_level.txt,sha256=CITDikHhRKAsSOGmNJzD-xSp6D5iBhSr9ZS1qy8-SL0,8
9
- portune-0.1.19.dist-info/RECORD,,