Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ping scan doesn't return mac address #43

Closed
0xN0x opened this issue Dec 28, 2020 · 7 comments
Closed

Ping scan doesn't return mac address #43

0xN0x opened this issue Dec 28, 2020 · 7 comments

Comments

@0xN0x
Copy link

0xN0x commented Dec 28, 2020

Hello,

When i execute the function nmap.nmap_ping_scan('192.168.1.0/24'), all hosts (50) have a "None" value as their mac address.
If i run the command /usr/bin/nmap -oX - -sP 192.168.1.0/24, i get the same results, no mac address.
But if i run this same command in sudo, i get the mac address.

Is there a parameter to run this command in sudo ?

Thanks you

@nmmapper
Copy link
Owner

Try running as root!

@0xN0x
Copy link
Author

0xN0x commented Dec 29, 2020

Even with running my script as root, i don't get them.

It's strange because the nmap process run as root, but the results of the function don't have the mac address even with this.

image

@nmmapper
Copy link
Owner

Unfortunately it seems not all hosts return mac addresses

@0xN0x
Copy link
Author

0xN0x commented Dec 29, 2020

All the hosts return a mac address if i run the nmap command myself, but they are not returned by the nmap_ping_scan function

@f-froehlich
Copy link
Contributor

I had the same (and a couple more) issues, In fact the xml parsing from the cli is not conform to the nmap DTD. You might want to use https://github.com/f-froehlich/nmap-scan. Note that you don't need root privileges to get the mac address and also you should never run a python script as root, if it's not really needed (which is not the case here)

@nmmapper
Copy link
Owner

nmmapper commented Jan 6, 2021

Try to use the latest changes from this repo not pip. There was a pull request #42 that fixed the mac addresses issue.

@nmmapper
Copy link
Owner

It so happens that you can't get mac address when you are not root. Also with Nmap you can't get the mac address of a remote machine https://stackoverflow.com/questions/13212187/is-it-possible-to-get-the-mac-address-for-machine-using-nmap.

If you run ping scan sudo nmap -sP 192.168.178.0/24 you should get mac addresses returned on your local network only.

Here is a sample(without root)

nmmapper@nmmapper:~$ nmap -sP 192.168.178.0/24
Starting Nmap 7.80 ( https://nmap.org ) at 2021-01-19 10:06 EAT
Nmap scan report for Lede.lan (192.168.178.1)
Host is up (0.0010s latency).
Nmap scan report for nmmapper.lan (192.168.178.95)
Host is up (0.00072s latency).
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.51 seconds
nmmapper@nmmapper:~$

Another sample(With root)

nmmapper@nmmapper:~$ sudo nmap -sP 192.168.178.0/24
[sudo] password for nmmapper: 
Starting Nmap 7.80 ( https://nmap.org ) at 2021-01-19 10:07 EAT
Nmap scan report for Lede.lan (192.168.178.1)
Host is up (0.0021s latency).
MAC Address: 00:7E:22:00:21:1C (Unknown)
Nmap scan report for 192.168.178.17
Host is up (0.0033s latency).
MAC Address: 38:63:BB:92:6C:AD (Hewlett Packard)
Nmap scan report for nmmapper.lan (192.168.178.95)
Host is up.
Nmap done: 256 IP addresses (3 hosts up) scanned in 2.04 seconds
nmmapper@nmmapper:~$ 

The same applies to this script when you run ping_scan with root it will return mac addresses

{
    "192.168.178.1": {
        "hostname": [
            {
                "name": "Lede.lan",
                "type": "PTR"
            }
        ],
        "macaddress": {
            "addr": "00:7E:22:00:21:1C",
            "addrtype": "mac"
        },
        "osmatch": {},
        "ports": [],
        "state": {
            "reason": "arp-response",
            "reason_ttl": "0",
            "state": "up"
        }
    },
    "192.168.178.17": {
        "hostname": [],
        "macaddress": {
            "addr": "38:63:BB:92:6C:AD",
            "addrtype": "mac",
            "vendor": "Hewlett Packard"
        },
        "osmatch": {},
        "ports": [],
        "state": {
            "reason": "arp-response",
            "reason_ttl": "0",
            "state": "up"
        }
    },
    "192.168.178.95": {
        "hostname": [
            {
                "name": "nmmapper.lan",
                "type": "PTR"
            }
        ],
        "macaddress": null,
        "osmatch": {},
        "ports": [],
        "state": {
            "reason": "localhost-response",
            "reason_ttl": "0",
            "state": "up"
        }
    },
    "runtime": {
        "elapsed": "2.02",
        "exit": "success",
        "summary": "Nmap done at Tue Jan 19 10:00:50 2021; 256 IP addresses (3 hosts up) scanned in 2.02 seconds",
        "time": "1611039650",
        "timestr": "Tue Jan 19 10:00:50 2021"
    },
    "stats": {
        "args": "/usr/bin/nmap -oX - -sP 192.168.178.0/24",
        "scanner": "nmap",
        "start": "1611039648",
        "startstr": "Tue Jan 19 10:00:48 2021",
        "version": "7.80",
        "xmloutputversion": "1.04"
    }
}

Without root privileges you won't get mac addresses


I Hope this helps I will close this issue in a few days!
nmmapper@nmmapper:~/Templates/dev/GitHub/python3-nmap/nmap3$ python3 nmap3.py  -d 192.168.178.0/24
{
    "192.168.178.1": {
        "hostname": [
            {
                "name": "Lede.lan",
                "type": "PTR"
            }
        ],
        "macaddress": null,
        "osmatch": {},
        "ports": [],
        "state": {
            "reason": "syn-ack",
            "reason_ttl": "0",
            "state": "up"
        }
    },
    "192.168.178.95": {
        "hostname": [
            {
                "name": "nmmapper.lan",
                "type": "PTR"
            }
        ],
        "macaddress": null,
        "osmatch": {},
        "ports": [],
        "state": {
            "reason": "conn-refused",
            "reason_ttl": "0",
            "state": "up"
        }
    },
    "runtime": {
        "elapsed": "3.01",
        "exit": "success",
        "summary": "Nmap done at Tue Jan 19 09:55:09 2021; 256 IP addresses (2 hosts up) scanned in 3.01 seconds",
        "time": "1611039309",
        "timestr": "Tue Jan 19 09:55:09 2021"
    },
    "stats": {
        "args": "/usr/bin/nmap -oX - -sP 192.168.178.0/24",
        "scanner": "nmap",
        "start": "1611039306",
        "startstr": "Tue Jan 19 09:55:06 2021",
        "version": "7.80",
        "xmloutputversion": "1.04"
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants