#!/usr/bin/env python
import optparse
def main():
p = optparse.OptionParser()
p.add_option('--person', '-p', default="world")
options, arguments = p.parse_args()
print 'Hello %s' % options.person
if __name__ == '__main__':
main()
Hello world
python hello_cli.py --help
Usage: hello_cli.py [options]
Options:
-h, --help show this help message and exit
-p PERSON, --person=PERSON
python hello_cli.py -p guido Hello guido
python hello_cli.py --name matz
Usage: hello_cli.py [options]
hello_cli.py: error: no such option: --name
arping from scapy import srp,Ether,ARP,conf conf.verb=0 ans,unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="10.0.1.1"), timeout=2) for snd, rcv in ans: print rcv.sprintf(r"%Ether.src% %ARP.psrc%")
sudo python arping.py
00:00:00:00:00:01 10.0.1.1
#!/usr/bin/env python
from scapy import srp,Ether,ARP,conf
def arping(iprange="10.0.1.0/24"):
conf.verb=0
ans,unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=iprange),
timeout=2)
collection = []
for snd, rcv in ans:
result = rcv.sprintf(r"%ARP.psrc% %Ether.src%").split()
collection.append(result)
return collection
#Print results
values = arping()
for ip,mac in values:
print ip,mac
#!/usr/bin/env python
import optparse
from scapy import srp,Ether,ARP,conf
def arping(iprange="10.0.1.0/24"):
"""Arping function takes IP Address or Network, returns nested mac/ip list"""
conf.verb=0
ans,unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=iprange),
timeout=2)
collection = []
for snd, rcv in ans:
result = rcv.sprintf(r"%ARP.psrc% %Ether.src%").split()
collection.append(result)
return collection
def main():
"""Runs program and handles command line options"""
p = optparse.OptionParser(description=' Finds MAC Address of IP address(es)',
prog='pyarping',
version='pyarping 0.1',
usage='%prog [10.0.1.1 or 10.0.1.0/24]')
options, arguments = p.parse_args()
if len(arguments) == 1:
values = arping(iprange=arguments)
for ip, mac in values:
print ip, mac
else:
p.print_help()
if __name__ == '__main__':
main()
if len(arguments) == 1:
values = arping(iprange=arguments)
sudo python arping.py 10.0.1.1
10.0.1.1 00:00:00:00:00:01
sudo python arping.py 10.0.1.1 10.0.1.3
Usage: pyarping [10.0.1.1 or 10.0.1.0/24]
Finds MAC Address or IP address(es)
Options:
--version show program's version number and exit
-h, --help show this help message and exit
if len(arguments) == 1:
values = arping(iprange=arguments)
for ip, mac in values:
print ip, mac
else:
p.print_help()
def main():
"""Runs program and handles command line options"""
p = optparse.OptionParser(description='Finds MAC Address of IP address(es)',
prog='pyarping',
version='pyarping 0.1',
usage='%prog [10.0.1.1 or 10.0.1.0/24]')
p.add_option('-m', '--mac', action ='store_true', help='returns only mac address')
p.add_option('-v', '--verbose', action ='store_true', help='returns verbose output')
options, arguments = p.parse_args()
if len(arguments) == 1:
values = arping(iprange=arguments)
if options.mac:
for ip, mac in values:
print mac
elif options.verbose:
for ip, mac in values:
print "IP: %s MAC: %s " % (ip, mac)
else:
for ip, mac in values:
print ip, mac
else:
p.print_help()
sudo python arping2.py
Password:
Usage: pyarping [10.0.1.1 or 10.0.1.0/24]
Finds MAC Address of IP address(es)
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-m, --mac returns only mac address
-v, --verbose returns verbose output
[ngift@M-6][H:11184][J:0]> sudo python arping2.py 10.0.1.1
10.0.1.1 00:00:00:00:00:01
[ngift@M-6][H:11185][J:0]> sudo python arping2.py -m 10.0.1.1
00:00:00:00:00:01
[ngift@M-6][H:11186][J:0]> sudo python arping2.py -v 10.0.1.1
IP: 10.0.1.1 MAC: 00:00:00:00:00:01
import subprocess
import re
def arping(ipaddress="10.0.1.1"):
"""Arping function takes IP Address or Network, returns nested mac/ip list"""
#Assuming use of arping on Red Hat Linux
p = subprocess.Popen("/usr/sbin/arping -c 2 %s" % ipaddress, shell=True,
stdout=subprocess.PIPE)
out = p.stdout.read()
result = out.split()
pattern = re.compile(":")
for item in result:
if re.search(pattern, item):
print item
arping()
#!/usr/bin/env python
import optparse
from storm.locals import *
from scapy import srp,Ether,ARP,conf
class NetworkRecord(object):
__storm_table__ = "networkrecord"
id = Int(primary=True)
ip = RawStr()
mac = RawStr()
hostname = RawStr()
def arping(iprange="10.0.1.0/24"):
"""Arping function takes IP Address or Network,
returns nested mac/ip list"""
conf.verb=0
ans,unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=iprange),
timeout=2)
collection = []
for snd, rcv in ans:
result = rcv.sprintf(r"%ARP.psrc% %Ether.src%").split()
collection.append(result)
return collection
def main():
"""Runs program and handles command line options"""
p = optparse.OptionParser()
p = optparse.OptionParser(description='Finds MACAddr of IP address(es)',
prog='pyarping',
version='pyarping 0.1',
usage= '%prog [10.0.1.1 or 10.0.1.0/24]')
options, arguments = p.parse_args()
if len(arguments) == 1:
database = create_database("sqlite:")
store = Store(database)
store.execute("CREATE TABLE networkrecord "
"(id INTEGER PRIMARY KEY, ip VARCHAR,\
mac VARCHAR, hostname VARCHAR)")
values = arping(iprange=arguments)
machine = NetworkRecord()
store.add(machine)
#Creates Records
for ip, mac in values:
machine.mac = mac
machine.ip = ip
#Flushes to database
store.flush()
#Prints Record
print "Record Number: %r" % machine.id
print "MAC Address: %r" % machine.mac
print "IP Address: %r" % machine.ip
else:
p.print_help()
if __name__ == '__main__':
main()
[AIX]
MAC: 00:00:00:00:02
IP: 10.0.1.2
Hostname: aix.example.com
[HPUX]
MAC: 00:00:00:00:03
IP: 10.0.1.3
Hostname: hpux.example.com
[SOLARIS]
MAC: 00:00:00:00:04
IP: 10.0.1.4
Hostname: solaris.example.com
[REDHAT]
MAC: 00:00:00:00:05
IP: 10.0.1.5
Hostname: redhat.example.com
[UBUNTU]
MAC: 00:00:00:00:06
IP: 10.0.1.6
Hostname: ubuntu.example.com
[OSX]
MAC: 00:00:00:00:07
IP: 10.0.1.7
Hostname: osx.example.com
#!/usr/bin/env python
import ConfigParser
def readConfig(file="config.ini"):
Config = ConfigParser.ConfigParser()
Config.read(file)
sections = Config.sections()
for machine in sections:
#uncomment line below to see how this config file is parsed
#print Config.items(machine)
macAddr = Config.items(machine)[0][1]
print machine, macAddr
readConfig()
OSX 00:00:00:00:07
SOLARIS 00:00:00:00:04
AIX 00:00:00:00:02
REDHAT 00:00:00:00:05
UBUNTU 00:00:00:00:06
HPUX 00:00:00:00:03
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有