swiftshadow 2.0.0__py3-none-any.whl → 2.0.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
swiftshadow/validator.py CHANGED
@@ -1,10 +1,47 @@
1
1
  import asyncio
2
+ import re
2
3
 
3
4
  import aiohttp
4
5
 
5
6
  from swiftshadow.models import Proxy
6
7
 
7
8
 
9
+ def find_ipv4_in_string(input_string: str) -> str | None:
10
+ """
11
+ Extract IPv4 Address from input and return the same.
12
+
13
+ Args:
14
+ input_string: Input string
15
+
16
+ Returns:
17
+ ipv4_address: If found
18
+ """
19
+ ipv4_pattern = r"\b((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\b"
20
+
21
+ match = re.search(ipv4_pattern, input_string)
22
+
23
+ if match:
24
+ return match.group(0)
25
+ else:
26
+ return None
27
+
28
+
29
+ async def get_host_ip(async_session: aiohttp.ClientSession) -> str | None:
30
+ """
31
+ Gets the hosts external IP for validation.
32
+
33
+ Args:
34
+ async_session: AioHTTP client session object
35
+
36
+ Returns:
37
+ text: Host IP
38
+ """
39
+ async with async_session.get("http://checkip.amazonaws.com") as response:
40
+ text = await response.text()
41
+ ip = find_ipv4_in_string(text)
42
+ return ip
43
+
44
+
8
45
  async def check_proxy(async_session: aiohttp.ClientSession, proxy: Proxy) -> str:
9
46
  """
10
47
  Check one proxy abject.
@@ -38,13 +75,22 @@ async def validate_proxies(proxies: list[Proxy]) -> list[Proxy]:
38
75
  working_proxies: list[Proxy] = []
39
76
  async with aiohttp.ClientSession() as async_session:
40
77
  tasks = []
78
+
79
+ host_task = asyncio.create_task(coro=get_host_ip(async_session))
80
+ tasks.append(host_task)
81
+
41
82
  for proxy in proxies:
42
83
  task = asyncio.create_task(coro=check_proxy(async_session, proxy))
43
84
  tasks.append(task)
85
+
44
86
  results = await asyncio.gather(*tasks, return_exceptions=True)
87
+ host_ip = results[0]
88
+ results = results[1:]
89
+
45
90
  for proxy, result in zip(proxies, results):
46
91
  if type(result) is not str:
47
92
  continue
48
- if result.count(".") == 3:
93
+ result_ip = find_ipv4_in_string(result)
94
+ if result_ip and result_ip != host_ip:
49
95
  working_proxies.append(proxy)
50
96
  return working_proxies
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: swiftshadow
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: Free IP Proxy rotator for python
5
5
  Author-email: sachin-sankar <mail.sachinsankar@gmail.com>
6
6
  License-File: LICENSE
@@ -6,9 +6,9 @@ swiftshadow/helpers.py,sha256=hHJ_JjRx2UFC5Ircl75LeYKBNDYTY_xMy2iWCk-UPqo,959
6
6
  swiftshadow/models.py,sha256=YyfZV98tPdLnF1O3WmTNUNoK4t0GuchfEftzjiM03ck,1678
7
7
  swiftshadow/providers.py,sha256=myJ6t-WD20wrjc7qDhxCpX1-oi7ipQutp34XKM2tjeI,5660
8
8
  swiftshadow/types.py,sha256=Alyw3n54OESX1vSR-0kTvpYTlJ8LKfy5J9WZbtglHpE,894
9
- swiftshadow/validator.py,sha256=dBcb6Lev6ojsk9f45IjyEUHZXsCcylyn6RoZA1WPDNQ,1345
10
- swiftshadow-2.0.0.dist-info/METADATA,sha256=MSM2WB68lsN__C1JiNwMH2sPMah2GrPUoCwyNbPoF9U,3261
11
- swiftshadow-2.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
- swiftshadow-2.0.0.dist-info/entry_points.txt,sha256=yMj0uEagcmXK2dmMmNXWebTpTT9j5K03oaRrd2wkyLA,49
13
- swiftshadow-2.0.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
14
- swiftshadow-2.0.0.dist-info/RECORD,,
9
+ swiftshadow/validator.py,sha256=z0dmRKxhvPETSXfC2hTImL0t8pw0zjSYIhUaDMJcJhU,2469
10
+ swiftshadow-2.0.1.dist-info/METADATA,sha256=Zj9Nw0u1cscQTrgtc6nBZvHRieCkH3-0r85YeWVp7b0,3261
11
+ swiftshadow-2.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
+ swiftshadow-2.0.1.dist-info/entry_points.txt,sha256=yMj0uEagcmXK2dmMmNXWebTpTT9j5K03oaRrd2wkyLA,49
13
+ swiftshadow-2.0.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
14
+ swiftshadow-2.0.1.dist-info/RECORD,,