Skip to content

Instantly share code, notes, and snippets.

@jgamblin

jgamblin/grepips.py

Created May 20, 2015
Embed
What would you like to do?
Python script to grep homepages on a subnet and will report if text is found.
#!/usr/bin/env python
# Name: grepips
# Purpose: #!/usr/bin/env python
# Name: grepips
# Purpose: grep a subnet and report if text is found.
# By: Jerry Gamblin
# Date: 20.05.15
# Modified 20.05.15
# Rev Level 0.1
## -----------------------------------------------
import os
import sys
import commands
from netaddr import IPNetwork
if len(sys.argv) != 3:
print("quickgrep subnet/24 string")
exit(0)
subnet = sys.argv[1]
s2g = sys.argv[2]
for ip in IPNetwork(subnet):
command = ("{0}{1}{2}{3}").format("lynx --source http://",ip," | grep -ci ",s2g)
bad = commands.getoutput(command)
if bad is '1':
print ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment