iiu module¶
Copyright 2014 Joel Montes de Oca <JoelMontes01@gmail.com>
This file is part of iiu.
iiu is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
iiu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with iuu. If not, see <http://www.gnu.org/licenses/>.
-
iiu.clean_list(lst)¶ Cleans the returned list to remove the trailing ‘,’
isitup.org returns a string with commas (‘,’), when the string is converted to a list, the list elements has a ‘,’ appended to the end of each element except for the last. This function removes the trailing comma from each element if it exists.
Example of dirty list: [‘Domain.com,’, ‘80,’, ‘1,’, ‘255.255.255.255,’, ‘301,’, ‘0.104’]
- ARG:
takes lst as the list with the trailing ‘,’
- Returns:
returns a new list without the trailing ‘,’
-
iiu.main()¶ iiu is a command line tool to aid system administrators when deploying or maintaining web servers. iiu is used to check if a web site is available from outside of your own network. It accomplishes this by using the freely available isitup.org API. iiu’s output is customizable making it simple to incorporate it into a script.
-
iiu.print_fancy(url)¶ Prints data in using multilines.
Takes the URL which the user would like to check and displays it on the screen using multi-lines. The reason for this print option is to be pleasing to the eyes of the user, it’s not meant to be used by scripts.
- data_list scheme:
- [‘domain’, ‘port’,
- ‘status code’, ‘response ip’,’response code’,
response time’]]
- ARG:
url - The URL which the user would like to check.
-
iiu.print_ip(url)¶ Prints only the IP address of the website.
Only prints the IP address of the URL entered. No time-stamp is provided in this mode. If time-stamp is needed then the ‘-r i’ should be used. This function is meant to be used as a shortcut to getting an IP address.
- ARGS:
url the URL of the site to check
-
iiu.print_return_only(url, args, label_state)¶ Returns only the information the user requests.
The print_return_only() takes url, args, and label_state as arguments and then prints on the screen the information the user wants.
- data_list scheme:
- [‘domain’, ‘port’, ‘status code’, ‘response ip’,
‘response code’, response time’]
- args_dic scheme:
- {user_options[order_index,
string to display, loc of data in data_list ]
- ARG:
url This is the URL the user wishes to check args The options chosen by the user to display label_state Whether the user wants to have the
information displayed with labels.
-
iiu.print_simple(url)¶ Prints a simple output.
Only requires a URL to function. The output is kept simple and consistant, can’t be customized.
The data_list consists of two nested lists. The first list is the status of the website, is it up down, etc, as determined by response_status(). The second list contains the data returned from isitup.org.
- data_list scheme:
[[status_of_site], [‘domain’, ‘port’,’status code’, ‘response ip’, ‘response code’, response time’]]
-
iiu.request_url(url)¶ Request body of the URL entered.
Requests the URL and returns the body of the page from http://isitup.org. It also cleans it using the clean_list(lst) function. Everything gets returned as a string.
- ARG:
url: the url that will be sent to http://isitup.org
- Returns:
returns the body of the http://isitup.org
-
iiu.response_status(lst)¶ Returns the status of the website along with the lst in a tuple.
Takes lst and checks to see if the website is one of the three states, then return the state of the site plus the list that was passed into response_status(lst).
States:
NONRESPONSIVE - Site does not return an IP address DOWN - Site is down but returns an IP UP - Site is up
- ARG:
- lst - The response from http:isitup.org after it
has been cleaned.
- RETURNS:
A tuple containing the state of the site as a string and the original list passed in.
-
iiu.sort_order(lst)¶ Takes a list of user chosen options and returns it in a predictable order.
Since dictionaries do not have a predictable order, this function takes the user’s options chosen and orders it in a perfectible manner. It does this by looking at the first number in the first list element. After the list is ordered, it returns the ordered list with the prefixed number stripped out (ex opt[2:]). The number prefix is hard coded in the print_return_only() function in the args_dic dictionary.
- ARG:
lst The list of chosen options by the user in random order
- RETURN:
ordered_lst The new list in a predictable order
-
iiu.time_stamp()¶ Produces a time stamp.
When called, it creates a time stamp and returns it.
Not sure if this function works as expectd under other platforms.
-
iiu.url_sanity(url)¶ Strips invalid prefixes from url.
isitup.org does not accept a URLs with a ‘http://’ or http: prefix. This function checks to see if the user entered the prefix and strips it from the url if so. ‘https://’ and ‘https:’ are also stripped.
- ARGS:
takes url as the URL the user entered
- RETURNS:
returns url with the invalid prefixes removed if found