I am creating a program to list out the ip address and users connected in the LAN. I done by getting the data by using nmap. Next i want to change the result data to a certain data frame using pandas or any other way. How to do it.
Here's the code:
import pandas as pd
import subprocess
from subprocess import Popen, PIPE
import re
def ipget():
i = 'nmap -sP 192.168.1.*'
output = subprocess.getoutput(i)
a = str(output).replace("Nmap","").replace("Starting 7.01 ( https://nmap.org ) at","").replace("scan report for","").replace("Host is up","").replace("latency","").replace("done: 256 IP addresses ","")
data = re.sub(r"(\(.*?\)\.)", "", a)
print(data)
#df = pd.DataFrame(data, columns = ['User', 'IP_Address'])
#print (df)
ipget()
the output stored in data and it is a string:
2019-05-21 18:19 IST
android-eb20919729f10e96 (192.168.1.8)
smackcoders (192.168.1.9)
princes-mbp (192.168.1.10)
shiv-mbp (192.168.1.15)
(4 hosts up) scanned in 18.35 seconds
Required output to be created in dataframe:
User IP_Address
android-eb20919729f10e96 192.168.1.8
smackcoders 192.168.1.9
princes-mbp 192.168.1.10
shiv-mbp 192.168.1.15