know-your-ip 0.2.1__tar.gz
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.
- know_your_ip-0.2.1/LICENSE +21 -0
- know_your_ip-0.2.1/PKG-INFO +315 -0
- know_your_ip-0.2.1/README.md +263 -0
- know_your_ip-0.2.1/know_your_ip/__init__.py +50 -0
- know_your_ip-0.2.1/know_your_ip/config.py +415 -0
- know_your_ip-0.2.1/know_your_ip/know_your_ip.py +991 -0
- know_your_ip-0.2.1/know_your_ip/ping.py +235 -0
- know_your_ip-0.2.1/know_your_ip/traceroute.py +49 -0
- know_your_ip-0.2.1/know_your_ip.egg-info/PKG-INFO +315 -0
- know_your_ip-0.2.1/know_your_ip.egg-info/SOURCES.txt +17 -0
- know_your_ip-0.2.1/know_your_ip.egg-info/dependency_links.txt +1 -0
- know_your_ip-0.2.1/know_your_ip.egg-info/entry_points.txt +2 -0
- know_your_ip-0.2.1/know_your_ip.egg-info/requires.txt +26 -0
- know_your_ip-0.2.1/know_your_ip.egg-info/top_level.txt +1 -0
- know_your_ip-0.2.1/pyproject.toml +123 -0
- know_your_ip-0.2.1/setup.cfg +4 -0
- know_your_ip-0.2.1/tests/test_config.py +185 -0
- know_your_ip-0.2.1/tests/test_package.py +40 -0
- know_your_ip-0.2.1/tests/test_utils.py +43 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2018 Suriyan Laohaprapanon and Gaurav Sood
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: know_your_ip
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Get data on IP addresses
|
|
5
|
+
Author-email: Suriyan Laohaprapanon <suriyant@gmail.com>, Gaurav Sood <gsood07@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/themains/know-your-ip
|
|
8
|
+
Project-URL: Repository, https://github.com/themains/know-your-ip
|
|
9
|
+
Project-URL: Documentation, https://themains.github.io/know-your-ip/
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/themains/know-your-ip/issues
|
|
11
|
+
Keywords: ip,geoip,ipvoid,abuseip,shodan,virustotal,blacklisted,geolocation,cybersecurity
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: System Administrators
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Internet
|
|
20
|
+
Classifier: Topic :: Security
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: System :: Networking
|
|
24
|
+
Classifier: Topic :: Utilities
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: geoip2
|
|
29
|
+
Requires-Dist: tzwhere
|
|
30
|
+
Requires-Dist: BeautifulSoup4
|
|
31
|
+
Requires-Dist: lxml
|
|
32
|
+
Requires-Dist: shodan
|
|
33
|
+
Requires-Dist: requests
|
|
34
|
+
Requires-Dist: pydantic>=2.0
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: ruff; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
39
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
40
|
+
Requires-Dist: build; extra == "dev"
|
|
41
|
+
Requires-Dist: twine; extra == "dev"
|
|
42
|
+
Provides-Extra: test
|
|
43
|
+
Requires-Dist: pytest; extra == "test"
|
|
44
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
45
|
+
Requires-Dist: pytest-mock; extra == "test"
|
|
46
|
+
Provides-Extra: docs
|
|
47
|
+
Requires-Dist: sphinx>=7.0; extra == "docs"
|
|
48
|
+
Requires-Dist: furo; extra == "docs"
|
|
49
|
+
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
50
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# Know Your IP
|
|
54
|
+
|
|
55
|
+
[](https://pypi.python.org/pypi/know_your_ip)
|
|
56
|
+
[](https://github.com/themains/know-your-ip/actions)
|
|
57
|
+
[](https://pepy.tech/project/know-your-ip)
|
|
58
|
+
|
|
59
|
+
Get comprehensive data on IP addresses. Learn where they are located (lat/long, country, city, time zone), whether they are flagged as malicious (by [AbuseIPDB](https://www.abuseipdb.com), [VirusTotal](https://www.virustotal.com), [IPVoid](https://ipvoid.com/), etc.), which ports are open and what services are running (via [Shodan](https://shodan.io)), and network diagnostics (ping, traceroute).
|
|
60
|
+
|
|
61
|
+
## 🚀 What's New in v0.2.0
|
|
62
|
+
|
|
63
|
+
- **Modern Configuration**: TOML-based config with Pydantic validation
|
|
64
|
+
- **VirusTotal API v3**: Latest API with enhanced threat intelligence
|
|
65
|
+
- **Embedded Categories**: Self-contained AbuseIPDB category mapping
|
|
66
|
+
- **Python 3.11+ Features**: Match/case syntax, union types, type safety
|
|
67
|
+
- **Performance Boost**: No file I/O for category lookups
|
|
68
|
+
- **Environment Variables**: Configuration via `KNOW_YOUR_IP_*` variables
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
### Installation
|
|
73
|
+
|
|
74
|
+
**Requirements**: Python 3.11+
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install know_your_ip
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Basic Usage
|
|
81
|
+
|
|
82
|
+
#### Command Line
|
|
83
|
+
```bash
|
|
84
|
+
# Analyze single IP
|
|
85
|
+
know_your_ip 8.8.8.8
|
|
86
|
+
|
|
87
|
+
# Analyze from file
|
|
88
|
+
know_your_ip --file input.csv --config config.toml
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Python Library
|
|
92
|
+
```python
|
|
93
|
+
from know_your_ip import KnowYourIPConfig, query_ip
|
|
94
|
+
|
|
95
|
+
# Load configuration
|
|
96
|
+
config = KnowYourIPConfig()
|
|
97
|
+
config.virustotal.enabled = True
|
|
98
|
+
config.virustotal.api_key = "your_api_key"
|
|
99
|
+
|
|
100
|
+
# Analyze IP
|
|
101
|
+
result = query_ip(config, "8.8.8.8")
|
|
102
|
+
print(result['virustotal.reputation']) # 530
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Configuration
|
|
106
|
+
|
|
107
|
+
### TOML Configuration File
|
|
108
|
+
|
|
109
|
+
Create `know_your_ip.toml`:
|
|
110
|
+
|
|
111
|
+
```toml
|
|
112
|
+
[maxmind]
|
|
113
|
+
enabled = true
|
|
114
|
+
db_path = "./db"
|
|
115
|
+
|
|
116
|
+
[abuseipdb]
|
|
117
|
+
enabled = true
|
|
118
|
+
api_key = "your_api_key_here"
|
|
119
|
+
days = 90
|
|
120
|
+
|
|
121
|
+
[virustotal]
|
|
122
|
+
enabled = true
|
|
123
|
+
api_key = "your_api_key_here"
|
|
124
|
+
|
|
125
|
+
[output]
|
|
126
|
+
columns = [
|
|
127
|
+
"ip",
|
|
128
|
+
"maxmind.country.names.en",
|
|
129
|
+
"virustotal.reputation",
|
|
130
|
+
"abuseipdb.categories"
|
|
131
|
+
]
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Environment Variables
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
export KNOW_YOUR_IP_VIRUSTOTAL_API_KEY="your_key"
|
|
138
|
+
export KNOW_YOUR_IP_VIRUSTOTAL_ENABLED=true
|
|
139
|
+
export KNOW_YOUR_IP_ABUSEIPDB_API_KEY="your_key"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Programmatic Configuration
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from know_your_ip import KnowYourIPConfig
|
|
146
|
+
|
|
147
|
+
config = KnowYourIPConfig()
|
|
148
|
+
config.virustotal.api_key = "your_api_key"
|
|
149
|
+
config.abuseipdb.enabled = True
|
|
150
|
+
config.abuseipdb.days = 30
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Supported Services
|
|
154
|
+
|
|
155
|
+
| Service | Features | API Required |
|
|
156
|
+
|---------|----------|--------------|
|
|
157
|
+
| **MaxMind** | Geolocation, ASN, ISP | Free database |
|
|
158
|
+
| **VirusTotal** | Threat reputation, categories | ✅ Free/Paid |
|
|
159
|
+
| **AbuseIPDB** | Abuse reports, categories | ✅ Free/Paid |
|
|
160
|
+
| **Shodan** | Open ports, services | ✅ Paid |
|
|
161
|
+
| **Censys** | Internet scanning data | ✅ Free/Paid |
|
|
162
|
+
| **IPVoid** | Blacklist status | Web scraping |
|
|
163
|
+
| **GeoNames** | Timezone data | ✅ Free |
|
|
164
|
+
| **Ping/Traceroute** | Network diagnostics | System tools |
|
|
165
|
+
|
|
166
|
+
### API Registration Links
|
|
167
|
+
|
|
168
|
+
- [VirusTotal](https://www.virustotal.com/gui/join-us) - 500 requests/day, 4/min free
|
|
169
|
+
- [AbuseIPDB](https://www.abuseipdb.com/register) - 1,000 requests/day free
|
|
170
|
+
- [Shodan](https://account.shodan.io/register) - Paid service ($69+/month)
|
|
171
|
+
- [Censys](https://search.censys.io/register) - 250 requests/month free
|
|
172
|
+
- [GeoNames](https://www.geonames.org/login) - 10,000 requests/day, 1,000/hour free
|
|
173
|
+
|
|
174
|
+
## Advanced Features
|
|
175
|
+
|
|
176
|
+
### Pandas Integration
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
import pandas as pd
|
|
180
|
+
from know_your_ip import load_config, query_ip
|
|
181
|
+
|
|
182
|
+
# Load IPs from CSV
|
|
183
|
+
df = pd.read_csv('ips.csv')
|
|
184
|
+
|
|
185
|
+
# Load configuration
|
|
186
|
+
config = load_config()
|
|
187
|
+
|
|
188
|
+
# Analyze all IPs
|
|
189
|
+
results = df['ip'].apply(lambda ip: pd.Series(query_ip(config, ip)))
|
|
190
|
+
results.to_csv('analysis.csv', index=False)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Custom Analysis
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from know_your_ip import maxmind_geocode_ip, virustotal_api
|
|
197
|
+
|
|
198
|
+
# Get only geolocation
|
|
199
|
+
location = maxmind_geocode_ip(config, "8.8.8.8")
|
|
200
|
+
print(f"Country: {location['maxmind.country.names.en']}")
|
|
201
|
+
|
|
202
|
+
# Get only threat intelligence
|
|
203
|
+
threat_data = virustotal_api(config, "8.8.8.8")
|
|
204
|
+
print(f"Malicious detections: {threat_data['virustotal.malicious']}")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Batch Processing
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
# Process large files with concurrency
|
|
211
|
+
know_your_ip --file large_ips.csv --max-conn 10 --config config.toml
|
|
212
|
+
|
|
213
|
+
# Process specific range
|
|
214
|
+
know_your_ip --file ips.csv --from 100 --to 200
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## API Reference
|
|
218
|
+
|
|
219
|
+
### Core Functions
|
|
220
|
+
|
|
221
|
+
- `query_ip(config, ip)` - Complete IP analysis
|
|
222
|
+
- `load_config(path)` - Load configuration from file
|
|
223
|
+
- `maxmind_geocode_ip(config, ip)` - Geolocation data
|
|
224
|
+
- `virustotal_api(config, ip)` - VirusTotal threat intel
|
|
225
|
+
- `abuseipdb_api(config, ip)` - Abuse reports
|
|
226
|
+
- `shodan_api(config, ip)` - Port/service data
|
|
227
|
+
- `ping(config, ip)` - Network latency
|
|
228
|
+
- `traceroute(config, ip)` - Network path
|
|
229
|
+
|
|
230
|
+
### Configuration Classes
|
|
231
|
+
|
|
232
|
+
- `KnowYourIPConfig` - Main configuration
|
|
233
|
+
- `MaxMindConfig` - Geolocation settings
|
|
234
|
+
- `VirusTotalConfig` - Threat intel settings
|
|
235
|
+
- `AbuseIPDBConfig` - Abuse data settings
|
|
236
|
+
- `OutputConfig` - Output column configuration
|
|
237
|
+
|
|
238
|
+
## Command Line Reference
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
usage: know_your_ip [-h] [-f FILE] [-c CONFIG] [-o OUTPUT] [-n MAX_CONN]
|
|
242
|
+
[--from FROM_ROW] [--to TO] [-v] [--no-header]
|
|
243
|
+
[ip [ip ...]]
|
|
244
|
+
|
|
245
|
+
Know Your IP - Comprehensive IP Address Analysis
|
|
246
|
+
|
|
247
|
+
positional arguments:
|
|
248
|
+
ip IP Address(es) to analyze
|
|
249
|
+
|
|
250
|
+
optional arguments:
|
|
251
|
+
-h, --help show this help message and exit
|
|
252
|
+
-f FILE, --file FILE List of IP addresses file
|
|
253
|
+
-c CONFIG, --config CONFIG
|
|
254
|
+
Configuration file (TOML format)
|
|
255
|
+
-o OUTPUT, --output OUTPUT
|
|
256
|
+
Output CSV file name
|
|
257
|
+
-n MAX_CONN, --max-conn MAX_CONN
|
|
258
|
+
Max concurrent connections
|
|
259
|
+
--from FROM_ROW From row number
|
|
260
|
+
--to TO To row number
|
|
261
|
+
-v, --verbose Verbose mode
|
|
262
|
+
--no-header Output without header
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Rate Limits
|
|
266
|
+
|
|
267
|
+
| Service | Free Tier | Paid Tier |
|
|
268
|
+
|---------|-----------|-----------|
|
|
269
|
+
| VirusTotal | 500/day, 4/min | Higher limits |
|
|
270
|
+
| AbuseIPDB | 1,000/day | 10,000+/day |
|
|
271
|
+
| Censys | 250/month, 1 req/2.5s | Higher limits |
|
|
272
|
+
| GeoNames | 10,000/day, 1,000/hour | Commercial plans |
|
|
273
|
+
| Shodan | No free API | $69+/month |
|
|
274
|
+
|
|
275
|
+
## Examples
|
|
276
|
+
|
|
277
|
+
See the [`examples/`](examples/) directory for:
|
|
278
|
+
- [example.py](examples/example.py) - Basic usage examples
|
|
279
|
+
- [example.ipynb](examples/example.ipynb) - Jupyter notebook tutorial
|
|
280
|
+
- [input.csv](examples/input.csv) - Sample input file
|
|
281
|
+
- [output.csv](examples/output.csv) - Sample output
|
|
282
|
+
|
|
283
|
+
## System Requirements
|
|
284
|
+
|
|
285
|
+
### Dependencies
|
|
286
|
+
- Python 3.11+
|
|
287
|
+
- System `traceroute` command (Linux) or `tracert` (Windows)
|
|
288
|
+
- Raw socket access for ping (requires admin/root privileges)
|
|
289
|
+
|
|
290
|
+
### Platform Support
|
|
291
|
+
- ✅ Linux
|
|
292
|
+
- ✅ macOS
|
|
293
|
+
- ✅ Windows
|
|
294
|
+
- ✅ Docker/containers
|
|
295
|
+
|
|
296
|
+
## Documentation
|
|
297
|
+
|
|
298
|
+
For comprehensive documentation, visit: [https://themains.github.io/know-your-ip/](https://themains.github.io/know-your-ip/)
|
|
299
|
+
|
|
300
|
+
## Contributing
|
|
301
|
+
|
|
302
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](https://contributor-covenant.org/version/1/0/0/).
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
Released under the [MIT License](https://opensource.org/licenses/MIT).
|
|
307
|
+
|
|
308
|
+
## Authors
|
|
309
|
+
|
|
310
|
+
- [Suriyan Laohaprapanon](https://github.com/soodoku)
|
|
311
|
+
- [Gaurav Sood](https://github.com/soodoku)
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
**Security Note**: This tool is designed for legitimate security analysis, threat intelligence, and network diagnostics. Please use responsibly and in accordance with applicable laws and service terms of use.
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# Know Your IP
|
|
2
|
+
|
|
3
|
+
[](https://pypi.python.org/pypi/know_your_ip)
|
|
4
|
+
[](https://github.com/themains/know-your-ip/actions)
|
|
5
|
+
[](https://pepy.tech/project/know-your-ip)
|
|
6
|
+
|
|
7
|
+
Get comprehensive data on IP addresses. Learn where they are located (lat/long, country, city, time zone), whether they are flagged as malicious (by [AbuseIPDB](https://www.abuseipdb.com), [VirusTotal](https://www.virustotal.com), [IPVoid](https://ipvoid.com/), etc.), which ports are open and what services are running (via [Shodan](https://shodan.io)), and network diagnostics (ping, traceroute).
|
|
8
|
+
|
|
9
|
+
## 🚀 What's New in v0.2.0
|
|
10
|
+
|
|
11
|
+
- **Modern Configuration**: TOML-based config with Pydantic validation
|
|
12
|
+
- **VirusTotal API v3**: Latest API with enhanced threat intelligence
|
|
13
|
+
- **Embedded Categories**: Self-contained AbuseIPDB category mapping
|
|
14
|
+
- **Python 3.11+ Features**: Match/case syntax, union types, type safety
|
|
15
|
+
- **Performance Boost**: No file I/O for category lookups
|
|
16
|
+
- **Environment Variables**: Configuration via `KNOW_YOUR_IP_*` variables
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
**Requirements**: Python 3.11+
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install know_your_ip
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Basic Usage
|
|
29
|
+
|
|
30
|
+
#### Command Line
|
|
31
|
+
```bash
|
|
32
|
+
# Analyze single IP
|
|
33
|
+
know_your_ip 8.8.8.8
|
|
34
|
+
|
|
35
|
+
# Analyze from file
|
|
36
|
+
know_your_ip --file input.csv --config config.toml
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Python Library
|
|
40
|
+
```python
|
|
41
|
+
from know_your_ip import KnowYourIPConfig, query_ip
|
|
42
|
+
|
|
43
|
+
# Load configuration
|
|
44
|
+
config = KnowYourIPConfig()
|
|
45
|
+
config.virustotal.enabled = True
|
|
46
|
+
config.virustotal.api_key = "your_api_key"
|
|
47
|
+
|
|
48
|
+
# Analyze IP
|
|
49
|
+
result = query_ip(config, "8.8.8.8")
|
|
50
|
+
print(result['virustotal.reputation']) # 530
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
### TOML Configuration File
|
|
56
|
+
|
|
57
|
+
Create `know_your_ip.toml`:
|
|
58
|
+
|
|
59
|
+
```toml
|
|
60
|
+
[maxmind]
|
|
61
|
+
enabled = true
|
|
62
|
+
db_path = "./db"
|
|
63
|
+
|
|
64
|
+
[abuseipdb]
|
|
65
|
+
enabled = true
|
|
66
|
+
api_key = "your_api_key_here"
|
|
67
|
+
days = 90
|
|
68
|
+
|
|
69
|
+
[virustotal]
|
|
70
|
+
enabled = true
|
|
71
|
+
api_key = "your_api_key_here"
|
|
72
|
+
|
|
73
|
+
[output]
|
|
74
|
+
columns = [
|
|
75
|
+
"ip",
|
|
76
|
+
"maxmind.country.names.en",
|
|
77
|
+
"virustotal.reputation",
|
|
78
|
+
"abuseipdb.categories"
|
|
79
|
+
]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Environment Variables
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
export KNOW_YOUR_IP_VIRUSTOTAL_API_KEY="your_key"
|
|
86
|
+
export KNOW_YOUR_IP_VIRUSTOTAL_ENABLED=true
|
|
87
|
+
export KNOW_YOUR_IP_ABUSEIPDB_API_KEY="your_key"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Programmatic Configuration
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from know_your_ip import KnowYourIPConfig
|
|
94
|
+
|
|
95
|
+
config = KnowYourIPConfig()
|
|
96
|
+
config.virustotal.api_key = "your_api_key"
|
|
97
|
+
config.abuseipdb.enabled = True
|
|
98
|
+
config.abuseipdb.days = 30
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Supported Services
|
|
102
|
+
|
|
103
|
+
| Service | Features | API Required |
|
|
104
|
+
|---------|----------|--------------|
|
|
105
|
+
| **MaxMind** | Geolocation, ASN, ISP | Free database |
|
|
106
|
+
| **VirusTotal** | Threat reputation, categories | ✅ Free/Paid |
|
|
107
|
+
| **AbuseIPDB** | Abuse reports, categories | ✅ Free/Paid |
|
|
108
|
+
| **Shodan** | Open ports, services | ✅ Paid |
|
|
109
|
+
| **Censys** | Internet scanning data | ✅ Free/Paid |
|
|
110
|
+
| **IPVoid** | Blacklist status | Web scraping |
|
|
111
|
+
| **GeoNames** | Timezone data | ✅ Free |
|
|
112
|
+
| **Ping/Traceroute** | Network diagnostics | System tools |
|
|
113
|
+
|
|
114
|
+
### API Registration Links
|
|
115
|
+
|
|
116
|
+
- [VirusTotal](https://www.virustotal.com/gui/join-us) - 500 requests/day, 4/min free
|
|
117
|
+
- [AbuseIPDB](https://www.abuseipdb.com/register) - 1,000 requests/day free
|
|
118
|
+
- [Shodan](https://account.shodan.io/register) - Paid service ($69+/month)
|
|
119
|
+
- [Censys](https://search.censys.io/register) - 250 requests/month free
|
|
120
|
+
- [GeoNames](https://www.geonames.org/login) - 10,000 requests/day, 1,000/hour free
|
|
121
|
+
|
|
122
|
+
## Advanced Features
|
|
123
|
+
|
|
124
|
+
### Pandas Integration
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import pandas as pd
|
|
128
|
+
from know_your_ip import load_config, query_ip
|
|
129
|
+
|
|
130
|
+
# Load IPs from CSV
|
|
131
|
+
df = pd.read_csv('ips.csv')
|
|
132
|
+
|
|
133
|
+
# Load configuration
|
|
134
|
+
config = load_config()
|
|
135
|
+
|
|
136
|
+
# Analyze all IPs
|
|
137
|
+
results = df['ip'].apply(lambda ip: pd.Series(query_ip(config, ip)))
|
|
138
|
+
results.to_csv('analysis.csv', index=False)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Custom Analysis
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from know_your_ip import maxmind_geocode_ip, virustotal_api
|
|
145
|
+
|
|
146
|
+
# Get only geolocation
|
|
147
|
+
location = maxmind_geocode_ip(config, "8.8.8.8")
|
|
148
|
+
print(f"Country: {location['maxmind.country.names.en']}")
|
|
149
|
+
|
|
150
|
+
# Get only threat intelligence
|
|
151
|
+
threat_data = virustotal_api(config, "8.8.8.8")
|
|
152
|
+
print(f"Malicious detections: {threat_data['virustotal.malicious']}")
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Batch Processing
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Process large files with concurrency
|
|
159
|
+
know_your_ip --file large_ips.csv --max-conn 10 --config config.toml
|
|
160
|
+
|
|
161
|
+
# Process specific range
|
|
162
|
+
know_your_ip --file ips.csv --from 100 --to 200
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## API Reference
|
|
166
|
+
|
|
167
|
+
### Core Functions
|
|
168
|
+
|
|
169
|
+
- `query_ip(config, ip)` - Complete IP analysis
|
|
170
|
+
- `load_config(path)` - Load configuration from file
|
|
171
|
+
- `maxmind_geocode_ip(config, ip)` - Geolocation data
|
|
172
|
+
- `virustotal_api(config, ip)` - VirusTotal threat intel
|
|
173
|
+
- `abuseipdb_api(config, ip)` - Abuse reports
|
|
174
|
+
- `shodan_api(config, ip)` - Port/service data
|
|
175
|
+
- `ping(config, ip)` - Network latency
|
|
176
|
+
- `traceroute(config, ip)` - Network path
|
|
177
|
+
|
|
178
|
+
### Configuration Classes
|
|
179
|
+
|
|
180
|
+
- `KnowYourIPConfig` - Main configuration
|
|
181
|
+
- `MaxMindConfig` - Geolocation settings
|
|
182
|
+
- `VirusTotalConfig` - Threat intel settings
|
|
183
|
+
- `AbuseIPDBConfig` - Abuse data settings
|
|
184
|
+
- `OutputConfig` - Output column configuration
|
|
185
|
+
|
|
186
|
+
## Command Line Reference
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
usage: know_your_ip [-h] [-f FILE] [-c CONFIG] [-o OUTPUT] [-n MAX_CONN]
|
|
190
|
+
[--from FROM_ROW] [--to TO] [-v] [--no-header]
|
|
191
|
+
[ip [ip ...]]
|
|
192
|
+
|
|
193
|
+
Know Your IP - Comprehensive IP Address Analysis
|
|
194
|
+
|
|
195
|
+
positional arguments:
|
|
196
|
+
ip IP Address(es) to analyze
|
|
197
|
+
|
|
198
|
+
optional arguments:
|
|
199
|
+
-h, --help show this help message and exit
|
|
200
|
+
-f FILE, --file FILE List of IP addresses file
|
|
201
|
+
-c CONFIG, --config CONFIG
|
|
202
|
+
Configuration file (TOML format)
|
|
203
|
+
-o OUTPUT, --output OUTPUT
|
|
204
|
+
Output CSV file name
|
|
205
|
+
-n MAX_CONN, --max-conn MAX_CONN
|
|
206
|
+
Max concurrent connections
|
|
207
|
+
--from FROM_ROW From row number
|
|
208
|
+
--to TO To row number
|
|
209
|
+
-v, --verbose Verbose mode
|
|
210
|
+
--no-header Output without header
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Rate Limits
|
|
214
|
+
|
|
215
|
+
| Service | Free Tier | Paid Tier |
|
|
216
|
+
|---------|-----------|-----------|
|
|
217
|
+
| VirusTotal | 500/day, 4/min | Higher limits |
|
|
218
|
+
| AbuseIPDB | 1,000/day | 10,000+/day |
|
|
219
|
+
| Censys | 250/month, 1 req/2.5s | Higher limits |
|
|
220
|
+
| GeoNames | 10,000/day, 1,000/hour | Commercial plans |
|
|
221
|
+
| Shodan | No free API | $69+/month |
|
|
222
|
+
|
|
223
|
+
## Examples
|
|
224
|
+
|
|
225
|
+
See the [`examples/`](examples/) directory for:
|
|
226
|
+
- [example.py](examples/example.py) - Basic usage examples
|
|
227
|
+
- [example.ipynb](examples/example.ipynb) - Jupyter notebook tutorial
|
|
228
|
+
- [input.csv](examples/input.csv) - Sample input file
|
|
229
|
+
- [output.csv](examples/output.csv) - Sample output
|
|
230
|
+
|
|
231
|
+
## System Requirements
|
|
232
|
+
|
|
233
|
+
### Dependencies
|
|
234
|
+
- Python 3.11+
|
|
235
|
+
- System `traceroute` command (Linux) or `tracert` (Windows)
|
|
236
|
+
- Raw socket access for ping (requires admin/root privileges)
|
|
237
|
+
|
|
238
|
+
### Platform Support
|
|
239
|
+
- ✅ Linux
|
|
240
|
+
- ✅ macOS
|
|
241
|
+
- ✅ Windows
|
|
242
|
+
- ✅ Docker/containers
|
|
243
|
+
|
|
244
|
+
## Documentation
|
|
245
|
+
|
|
246
|
+
For comprehensive documentation, visit: [https://themains.github.io/know-your-ip/](https://themains.github.io/know-your-ip/)
|
|
247
|
+
|
|
248
|
+
## Contributing
|
|
249
|
+
|
|
250
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](https://contributor-covenant.org/version/1/0/0/).
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
Released under the [MIT License](https://opensource.org/licenses/MIT).
|
|
255
|
+
|
|
256
|
+
## Authors
|
|
257
|
+
|
|
258
|
+
- [Suriyan Laohaprapanon](https://github.com/soodoku)
|
|
259
|
+
- [Gaurav Sood](https://github.com/soodoku)
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
**Security Note**: This tool is designed for legitimate security analysis, threat intelligence, and network diagnostics. Please use responsibly and in accordance with applicable laws and service terms of use.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Know Your IP
|
|
2
|
+
|
|
3
|
+
A Python package to get comprehensive data about IP addresses including:
|
|
4
|
+
- Geolocation (latitude/longitude, country, city, timezone)
|
|
5
|
+
- Security analysis (blacklist status via multiple services)
|
|
6
|
+
- Network information (open ports, running services)
|
|
7
|
+
- Network diagnostics (ping, traceroute)
|
|
8
|
+
|
|
9
|
+
Supports multiple data sources including MaxMind, AbuseIPDB, VirusTotal,
|
|
10
|
+
Shodan, Censys, and more.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from importlib.metadata import version
|
|
14
|
+
|
|
15
|
+
__version__ = version("know_your_ip")
|
|
16
|
+
|
|
17
|
+
from .config import KnowYourIPConfig, load_config
|
|
18
|
+
from .know_your_ip import (
|
|
19
|
+
abuseipdb_api,
|
|
20
|
+
abuseipdb_web,
|
|
21
|
+
apivoid_api,
|
|
22
|
+
censys_api,
|
|
23
|
+
geonames_timezone,
|
|
24
|
+
ipvoid_scan,
|
|
25
|
+
maxmind_geocode_ip,
|
|
26
|
+
ping,
|
|
27
|
+
query_ip,
|
|
28
|
+
shodan_api,
|
|
29
|
+
traceroute,
|
|
30
|
+
tzwhere_timezone,
|
|
31
|
+
virustotal_api,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"KnowYourIPConfig",
|
|
36
|
+
"load_config",
|
|
37
|
+
"maxmind_geocode_ip",
|
|
38
|
+
"geonames_timezone",
|
|
39
|
+
"tzwhere_timezone",
|
|
40
|
+
"ipvoid_scan",
|
|
41
|
+
"abuseipdb_web",
|
|
42
|
+
"abuseipdb_api",
|
|
43
|
+
"censys_api",
|
|
44
|
+
"shodan_api",
|
|
45
|
+
"virustotal_api",
|
|
46
|
+
"ping",
|
|
47
|
+
"traceroute",
|
|
48
|
+
"query_ip",
|
|
49
|
+
"apivoid_api",
|
|
50
|
+
]
|