When i try to run my code through a kali bootable usb stick it doesnt work as in the course

when i try to run the code that Zaid Al Quraishi explained in his course it doesn’t work(course name is “learn python and ethical hacking from scratch”), it works on the virtual machine but not on a kali Linux bootable stick and i wanted to know why it doesn’t work the code is exactly like in the course but I think it it my problem because i tried with other codes that should have done the same thing but that doesn’t work too and yes i tried to put my_router_ip_address/24 to scan every device but it still doesn’t work.

Does your bootable Kali have persistence enabled?

yes it does and to mention i dont have a account i use the root account or more like the user kali/kali and i use the terminal with root privilegies that the usb gives me without making a personal account

Can i contact Zaid somehow?

What scripts are you running? There are multiple scripts in that course. Which ones have you tried and it didn’t run on bootable Kali?

i tried a network scan and a arp spoofer and both dont work.

Do you get any specific errors when you run nmap or arp spoof or it just doesn’t do anything? If you get errors, please post screenshot for that

no for nmap and arpspoof the already made tools i get no errors they are working as intended even fping is working better than my code

Wait are you saying the tools are working but your code is not working? Share the code you are running exactly and the screenshot too. I don’t understand what is not working


If You can see these photos You can see that nmap shows more than my code the ip that ends with 131 is the target and the ip that ends with 1 is the router i want to mention that i dont Have a account in this bootable kali so this might be the problem


The don’t see the host ending with 0.131 in your namp report. It’s not finding the 0.132 host when you run the python code and that’s why it’s giving the error

The 131 host wasnt connected then and i cant send screenshots with the host but as You saw nmap works and shows whats in my network while my code only shows the router ip and mac

Start debugging something like this:
inside scan function, just run arping like: print(arping(ip)) to check what the response is. If you are getting both IPs then something is wrong with ARP function. If you are not getting two IPs then I am not sure if it is something to do with scapy in general not working. Also you said this same code prints all IPs when you run in a VM?

Yes it prints all the ips on VM now i cant debbug because im in another country and i will arrive home in like 7 days so You can take a break for now.

i came back and with not so good news i tried to put your print in my code and after doing that and instaling scapy since it was giving me errors about not having scapy idk why because pycharm had scapy and when i run my code it only gives me the router ip as alive thats the same for nmap and fping but these already built tools do give me addicionally more ips i think there are some other thing with my router because idk what liteon tehnology is(now i had my 192.168.0.113 victim connected to the same network so we should see more), but when i run arp -a it shows me the victim with its mac and ip which is very wierd because arp -a should only show other devices in the network only if it had any connection with the device that is scanning so maybe fping or nmap done something to print that in the arp table


Hello @No0bYebY,

as @Apurv-StationX correctly said:

The host you were trying to reach was not found by the function scapy.all.srp.
As a result you get no answer from that host.

Your OS is working fine, the problem is the python script not being very clear what the problem is (host not found).

Detailed Walkthrough:

Read more

Let’s try the following lines of code:

import scapy.all as scapy

ether = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp = scapy.ARP(pdst="192.168.0.1")
ans, unans = scapy.srp(ether/arp, timeout=1)

The tuple (ans, unans) returned by the function srp has the following values:

If the host is up:

Variable values
  • ans = <Results: TCP:0 UDP:0 ICMP:0 Other:1>
  • unans = <Unanswered: TCP:0 UDP:0 ICMP:0 Other:0>

If the host is down:

Variable values
  • ans = <Results: TCP:0 UDP:0 ICMP:0 Other:0>
  • unans = <Unanswered: TCP:0 UDP:0 ICMP:0 Other:1>

Now what happens if we try to index these variables like you are doing in your code?

If the host is up:

Variable values
  • ans[0] = QueryAnswer(
    query=<Ether dst=ff:ff:ff:ff:ff:ff type=ARP |<ARP pdst=192.168.0.1 |>>,
    answer=<Ether dst=58:D9:D5:DD:67:A0 src=8E:99:FA:64:0B:E2 type=ARP |<ARP hwtype=0x1 ptype=IPv4 hwlen=6 plen=4 op=is-at hwsrc=8E:99:FA:64:0B:E2 psrc=192.168.0.1 hwdst=58:D9:D5:DD:67:A0 pdst=192.168.0.178 |<Padding load=’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00’ |>>>)

  • unans[0] = Traceback (most recent call last):
    [...]
    return self.res.__getitem__(item)
    IndexError: list index out of range


If the host is down:

Variable values
  • ans[0]= Traceback (most recent call last):
    [...]
    return self.res.__getitem__(item)
    IndexError: list index out of range

  • unans[0] = <Ether dst=ff:ff:ff:ff:ff:ff type=ARP |<ARP pdst=192.168.0.1 |>>


Interesting! Now that’s exactly what the console output in your screenshot looks like!
Indexing the variable “ans” returns an IndexError, when the host is offline.

Solution:

Use try/except to catch and handle the IndexError (only the IndexError, not all errors!!).

import scapy.all as scapy

ether = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp = scapy.ARP(pdst="192.168.0.1")
ans, unans = scapy.srp(ether/arp, timeout=1)

try:
    # do something with the variable ans
    print(ans[0])
except IndexError:
    # Code to handle error
    print("The host you were trying to reach did not answer!")

For further information please read the documentation at:
Usage — Scapy 2.4.5. documentation