Created
May 23, 2012 12:04
-
-
Save benmezger/2774857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
""" | |
Author: Ephexeve M | |
Date: Mon May 21 11:48:10 CEST 2012 | |
System: Unix | |
""" | |
import pages | |
from sys import argv, exit | |
import httplib | |
import socket | |
from optparse import OptionParser | |
parser = OptionParser() | |
parser.add_option("-w", "--write", dest = "filename", help = "write report to file", metavar = "FILE") | |
(options, args) = parser.parse_args() | |
class GetPages: | |
def __init__(self): | |
try: | |
self.site = argv[1] | |
except IndexError as error: | |
print "\nError, where is the link? -- %s" % error | |
exit(0) | |
self.write = argv[2] if len(argv) >= 3 else False | |
self.filename = argv[3] if len(argv) >= 4 else False | |
self.checkSite = self.checkSite() | |
def checkSite(self): | |
if not self.site.startswith("www."): | |
self.site = "www." + self.site | |
try: | |
for pagelinks in pages.links: | |
pagelinks = pagelinks.replace("\n", "") ; pagelinks = "/" + pagelinks | |
host = self.site + pagelinks | |
site_connection = httplib.HTTPConnection(self.site) | |
site_connection.request("GET", host) | |
response = site_connection.getresponse() | |
if response.status: | |
print "%s Status: %s" % (host, response.status) | |
if self.write: | |
for status in response.status: | |
with open(self.filename, "w") as data: | |
data.write(host + "--" + status + "\n") | |
except Exception as error: | |
return "Error occured: %s" % error | |
if __name__ == "__main__": | |
GetPages() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment