<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Netscan
Here is a sample of some the capabilities of the netscan library.
Step1:  Get host info
On macOS or Linux, GetHostName should be able to resolve a computer's IP address to a hostname.
Step2:  WhoIs uses a REST API to recover a current record of an external IP address.
Step3:  MacLookup uses a REST API to turn a MAC address into a vendor name.
Step4:  Commands
Unfortunately it is difficult in python to execute simple commands and get the returned output. This is a simple wrapper around the obnoxiously complex subprocess command in Python.
Step5:  Passive Scanning
Unfortunately I currently don't know how to run python code in a jupyter notebook using sudo. Therefore I can't do live captures. Instead I will use a pcap.
Step6:  Active Scanning
Don't know how to do this using sudo.
<ASSISTANT_TASK:>
Python Code:
from __future__ import print_function
from netscan.lib import WhoIs, GetHostName, MacLookup, Commands
import pprint as pp
Explanation: Netscan
Here is a sample of some the capabilities of the netscan library.
End of explanation
print(GetHostName('192.168.1.13').name)
print(GetHostName('127.0.0.1').name)
Explanation: Get host info
On macOS or Linux, GetHostName should be able to resolve a computer's IP address to a hostname.
End of explanation
pp.pprint(WhoIs('216.58.217.4').record)
info = WhoIs('216.58.217.4')
print('CIDR:', info.CIDR)
print('Organization:', info.Organization)
Explanation: WhoIs uses a REST API to recover a current record of an external IP address.
End of explanation
print(MacLookup('58:b0:35:f2:55:88').vendor)
Explanation: MacLookup uses a REST API to turn a MAC address into a vendor name.
End of explanation
cmd = Commands()
ret = cmd.getoutput('ls -alh')
print(ret)
print(Commands().getoutput('echo hi'))
Explanation: Commands
Unfortunately it is difficult in python to execute simple commands and get the returned output. This is a simple wrapper around the obnoxiously complex subprocess command in Python.
End of explanation
from netscan.PassiveScan import PassiveMapper
nmap = []
pm = PassiveMapper()
nmap = pm.pcap('../tests/test.pcap')
nmap = pm.filter(nmap)
nmap = pm.combine(nmap)
nmap = pm.combine(nmap)
pp.pprint(nmap)
Explanation: Passive Scanning
Unfortunately I currently don't know how to run python code in a jupyter notebook using sudo. Therefore I can't do live captures. Instead I will use a pcap.
End of explanation
from netscan.ActiveScan import ActiveMapper
am = ActiveMapper(range(1, 1024))
hosts = am.scan('en1')
pp.pprint(hosts)
print(GetHostName('192.168.1.13').name)
Explanation: Active Scanning
Don't know how to do this using sudo.
End of explanation
<END_TASK>