Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit14ce0f7

Browse files
committed
add reverse lookup tutorial
1 parent98e4e34 commit14ce0f7

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
6969
-[How to Make Malware Persistent in Python](https://thepythoncode.com/article/how-to-create-malware-persistent-in-python). ([code](ethical-hacking/persistent-malware))
7070
-[How to Remove Persistent Malware in Python](https://thepythoncode.com/article/removingg-persistent-malware-in-python). ([code](ethical-hacking/remove-persistent-malware))
7171
-[How to Check Password Strength with Python](https://thepythoncode.com/article/test-password-strength-with-python). ([code](ethical-hacking/checking-password-strength))
72+
-[How to Perform Reverse DNS Lookups Using Python](https://thepythoncode.com/article/reverse-dns-lookup-with-python). ([code](ethical-hacking/reverse-dns-lookup))
7273

7374
-###[Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
7475
-###[Natural Language Processing](https://www.thepythoncode.com/topic/nlp)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#[How to Perform Reverse DNS Lookups Using Python](https://thepythoncode.com/article/reverse-dns-lookup-with-python)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Import the necessary libraries
2+
importargparse
3+
importipaddress
4+
importsocket
5+
importrequests
6+
7+
API_KEY="Your-Api-Key-Here"# Replace with your ViewDNS API key
8+
9+
# Function to Check if IP address is valid.
10+
defis_valid_ip(ip):
11+
12+
try:
13+
ipaddress.ip_address(ip)
14+
returnTrue
15+
exceptValueError:
16+
returnFalse
17+
18+
19+
# Perform reverse look up.
20+
defreverse_lookup(ip):
21+
try:
22+
domain=socket.gethostbyaddr(ip)[0]
23+
returndomain
24+
exceptsocket.herror:
25+
returnNone
26+
27+
28+
# Get websites on same server.
29+
defget_websites_on_server(ip):
30+
url=f"https://api.viewdns.info/reverseip/?host={ip}&apikey={API_KEY}&output=json"
31+
response=requests.get(url)
32+
ifresponse.status_code==200:
33+
data=response.json()
34+
if"response"indataand"domains"indata["response"]:
35+
websites=data["response"]["domains"]
36+
returnwebsites
37+
return []
38+
39+
40+
# Get user arguments and execute.
41+
defmain():
42+
parser=argparse.ArgumentParser(description="Perform IP reverse lookup.")
43+
parser.add_argument("ips",nargs="+",help="IP address(es) to perform reverse lookup on.")
44+
parser.add_argument("--all","-a",action="store_true",help="Print all other websites on the same server.")
45+
args=parser.parse_args()
46+
47+
foripinargs.ips:
48+
ifnotis_valid_ip(ip):
49+
print(f"[-] Invalid IP address:{ip}")
50+
continue
51+
52+
domain=reverse_lookup(ip)
53+
ifdomain:
54+
print(f"[+] IP:{ip}, Domain:{domain}")
55+
ifargs.all:
56+
websites=get_websites_on_server(ip)
57+
ifwebsites:
58+
print("\nOther websites on the same server:")
59+
forwebsiteinwebsites:
60+
print(f"[+]{website}")
61+
print('\n')
62+
else:
63+
print("[-] No other websites found on the same server.")
64+
else:
65+
print(f"[-] No domain found for IP:{ip}")
66+
67+
68+
if__name__=="__main__":
69+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp