iiu module¶
Copyright 2014-2019 Joel Montes de Oca <JoelMontes01@gmail.com>
iiu (Is It Up?) is a command line tool used to check if a website 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 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
Dirty List:
[‘Domain.com,’, ‘80,’, ‘1,’, ‘255.255.255.255,’, ‘301,’, ‘0.104’]
- Parameters
lst (list) – List to be cleaned
- Returns
A new list with the trailing ‘,’ removed
- Return type
list
-
iiu.main()¶ The main function of iiu
-
iiu.print_fancy(url)¶ Prints data using multi-lines
Takes the URL which the user would like to check and displays it on the screen using multiple lines. This mode is meant to look nice and be easy to read for the user.
- Example
data_list scheme:
[‘domain’, ‘port’, ‘status code’, ‘response ip’,’response code’, response time’]
- Parameters
url – he URL which the user would like to check
- Returns
0
-
iiu.print_ip(url)¶ Prints only the IP address of the website
Only prints the IP address of the URL entered. 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.
- Parameters
url (str) – The URL of the site to be checked
:return 0
-
iiu.print_return_only(url, args, label_state)¶ Returns only the information the user requests
The print_return_only function takes the arguments the user wants and prints them.
- 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 ]}
- Parameters
url (str) – The URL to be checked
args – The options the user would like to have printed
label_state – Whether the user wants to have the information displayed with labels.
- Returns
0
-
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.
- Parameters
url (str) – The url that will be sent to http://isitup.org
return: The body of the http://isitup.org :rtype:str
-
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
- Parameters
lst – The response from http:isitup.org after it has been cleaned.
:type lst:str
- Returns
The state of the site as a string and the original list passed in.
- Return type
tuple
-
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.
- Parameters
lst (list) – The list of chosen options by the user in random order
- Returns
The new list in a predictable order
- Return type
list
-
iiu.time_stamp()¶ Produces a time stamp
When time_stamp is called, it creates a time stamp and returns it.
Warning
Not sure if this function works as expected under other platforms.
- Returns
Current timestamp
-
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:8 are also stripped.
- Parameters
url – The URL entered by the user
- Returns
The URL with the invalid prefixes removed if found