Week 3: Networking Tools and Learning Python
This week I went over the last three tools from the Introductory Networking THM module. The first tool I explored was called Traceroute. It maps the path a request takes when heading to a target machine since it has to pass by many different servers.
This is what is typed into the terminal: traceroute
The Windows traceroute utility (tracert) operates using the same ICMP protocol that ping utilizes; the Unix equivalent operates with UDP
This is what is typed into the terminal to use TCP SYN requests when tracing the route: traceroute -T
The room also explained Domain Names. A domain name represents an IP address and domain registrars lease said domain names out. Whois can show who owns a domain.
Then it explained the Dig tool, which essentially allows a user to manually query recursive DNS servers to find information about a domain. This is what is typed into the terminal: dig @
Here's an explanation of what a request does to a domain:
The computer checks the local Hosts Files to see if an explicit IP to domain map has been created (this is mostly done with older systems and is less commonly used)
The computer then checks local DNS cache if host file has nothing
If still nothing is found, the computer sends a request to the recursive DNS server, which the router on the network automatically knows since the ISP has their own recursive servers that it provides to the computer. But if the the IP address is not in the cache then it goes to the root name server.
There are 13 main root name DNS that keep track of DNS servers in the next level which are the Top Level Domain servers.
The Top Level Domain servers TLD are split into extensions. For example, if looking for xyz.com then TLD server with .com domains would be searched instead of .co, then it moves onto the next level which is the Authoritative name servers
The Authoritative name servers store DNS records for the domains directly
The Dig tool is good for network troubleshooting. Once used, the ANSWER tag states the IP address and a lot of other information. The TTL (Time to Live) states when a record stops being valid, so that the computer doesn't rely on the cache, and it is in the second column next to the domain name, measured in seconds.
I then started the Network Services THM module and the FreeCodeCamp Python course. I thought I could get the Python basics down quickly to start my next project: A Packet Sniffer! I might need more time to complete the Python course before building a packet sniffer, but it's been fun so far. I didn't expect to build such simple projects within the course itself. The lessons are also small enough to get through within an hour or less. The workshops are really my favorite part.
I learned that Python 2 should not be used for any new code since it's at the end of its life. The course did explain how to install Python, but I installed Python some time ago. I remember having an issue with it because I hadn't clicked 'add pthon.exe to path' when installing it.
Variables are declared by using the equal sign (=) assignment operator. For example:
name = 'Jane'
age = 25
The series of characters used to represent text is a string and single or double quotes are used around the string, such as 'Jane'.
variables can only start with a letter or _ underscore, no numbers
variable names can only have alphanumeric characters upper/lower case, 0-9 and underscores
variable names are case sensitive (age Age AGE are all different variables)
variable names can't be reserved keywords such as: if, class, or def
snakecase: variable names in lowercase with separate words separated by underscore, example: this_is_a_variable_name = 'SecureByHabit'
The course explained that the names of variables should be descriptive, such as "user_age" instead of simply "age", in order to communicate the purpose of said variable. Then it mentioned comments start with a pound symbol (#). So if there's a need for a multi-line comment, just add a pound symbol at the front.
The Print Function was also explained; it outputs data to the terminal, such as print('thisisastring'). It also showcased that spaces are added when separate quotation marks with commas outside each ending quotation mark are used. For example:
print('the,numbers,are,1,2,3') would output: the,numbers,are,1,2,3
print('the','numbers','are','1','2','3') would output: the numbers are 1 2 3
Then it explained that each data type describes the kind of value a variable holds, which makes it faster and easier to use Python. Python, like JavaScript, is dynamically typed based on what is assigned to it. Python automatically understands that a string uses single or double quotation marks and that a number is an integer. Unlike static languages, like C#, Java, and C++, which require typing out the data type, such as string name = 'Jane' or int age = 25. BUT python sometimes has type errors that can only be detected when the program runs, so unexpected bugs pop up. On the bright side, since Python runs code line by line, it stops once it finds a line with an error. Some languages, in contrast, compile before running so they catch errors before running the program.
There are 10 Data Types:
Integer: whole number without decimals such as 10 or -5
Float: number with a decimal point like 4.41 or -0.4
String: sequence of characters enclosed in a single or double quotation marks
Boolean: true or false type, written as True or False, class typed as bool
Set: unordered collection of unique elements, like {7, 5.6, 'hello'}
Dictionary: collection of key value pairs enclosed in curly braces like {'name': 'Jane','age':28}, class typed as dict
Tuple: immutable ordered collection enclosed in parentheses like ('apple',4.5,7)
Range: sequence of numbers often used in loops, such as range(9)
List: ordered collection of elements that supports different data types
None: special value represents the absence of a value, class type is NoneType
To get the data type of a value use the type() function. The built in isinstance() function checks if a variable matches a specific data type, then returns a boolean. The isinstance() can check if a number is an int or float by printing a bool: print(isinstance(score, int)). After this explanation, I built a report card by assigning values, printing said values, and printing their types! I like that the workshops immediately let me test the material they explained.
The next module is called Strings & String Immutability. It started by explaining that a multiline string can use triple double-quotes or single-quotes like so:
- my_str_3 = """Multiline string"""
And if a string includes a quotation mark, use the opposite type so it shows up, such as, 'She said, "Hello!"' Or use a slash, like so: "She said, \"Hello!\""
They also stated that, to check if a string contains one or more characters, an in operator can be used to check. For example: my_str = 'Hello world' then print('Hello' in my_str) returns True because Hello is present in the string.
It also explained that indexing is a process to get the length of a string and to work with individual characters.
len() gives length, example: print(len(my_str)) and will output 11
Each character has a position called an index, which is zero based. Meaning it starts with 0 and the second character would be 1, etc. Square brackets are used to access a character by its index. For example: print(my_str[0]) and it'll print H. Negative indexing allows the use of a negative number to get the last characters in a string. For example: -1 would be d and -2 l.
Then it mentioned that all data in Python are objects and some are immutable, while others are mutable. Immutable data types can't be modified or altered once declared, but can be reassigned, but can't change the original object by altering elements
strings, integers, float, boolean, tuple and range are immutable in python
reassigning entails pointing the variable to a different string like so:
greeting = 'hi'
greeting = 'hello'
print(greeting) and it'll print hello since its been reassigned
The next module is String Concatenation and String Interpolation:
String Concatenation: combines multiple strings with plus sign (+) operator
Str_plus_str = my_str + ' ' + my_str_1
print(str_plus_str)
I had the hardest time with this particular module when applying the information to the workshop project. I highly recommend trying that project. Anyways, a string can't concatenate with a number. However, a number can be converted to a string by using str(), for example: name_and_age = name + str(age) The += combination can also be used, it concatenates and assigns in one step. String interpolation is the process of inserting variables and expressions into a string.
F-strings are formatted string literals, allowing the handling of interpolation with a compact and readable syntax. F-strings start with an f before quotes and allows the embedment of variables or expressions inside curly braces {}. For example:
- name_and_age = f'My name is {name} and I am {age} years old'
There's no need to use a str() function cause variables convert into a string during the interpolation process, just remember to use the single quotation marks and the curly braces only go around the variables that are to be embedded.
The last module I explored is titled String Slicing. String slicing allows the extraction of a portion of a string with only a specific part of it: string[start:stop]. For example:
- print(my_str[1:4]) and it'll print ell
The stop is non-inclusive, meaning it stops right before the stop index so in the example above, it only printed out 1-3 of Hello. Remember that H is 0. Also, the start or stop can be omitted and it'll stop at the end or start at the beginning. For example:
- print(my_str[:7]) returns Hello w (the space is counted)
Slicing doesnt modify the original string. And if everything is omitted then it prints the whole thing
- my_str[:]
The step parameter specifies the increment between each index in the slice. For example:
- my_str = 'Hello world' print(my_str[0:11:2]) and it prints Hlowrd
A string can also be reversed by using -1 as a step. For example:
- print(my_str[::-1]) and it prints dlrow olleh
Then it listed the Common String Methods:
upper(): converts all characters to upper case .upper
lower(): converts all characters to lower case .lower
strip(): new string with specified leading and trailing characters removed, or any white spaces that are leading/trailing
replace(old, new): returns a new string that replaces all old occurrences with new ones, example:
- my_str.replace(hello,hi) will now print hi world instead of hello world
split(separator): splits a string on specified separator into list of strings but if nothing is specified then it splits on whitespaces, example:
- my_str.split() prints ['hello', 'world'] from 'hello world'
join(iterable): joins elements of an iterable into a string with a separator, example:
- if my_list = ['hello', 'world'] turns into hello world when using ' '.join(my_list)
startswith(prefix): returns boolean indicating if a string starts with the specified prefix, example:
- my_str.startswith('hello') and it'll say true cause it starts with hello
endswith(suffix): returns boolean indicating if a string ends with the specified suffix
find(substring): returns index of the first occurrence of substring or -1 if it doesnt fine one, for example:
- my_str.find('world') would return 6 so it wont include the very index of the w letter
count(substring): returns number of times a substring appears in string, for example:
- my_str.count('o') would give back a 2
capitalize(): returns a new string with the first letter capitalized and the rest lowercase
isupper(): returns true if all letters in the string are uppercase and false if not
islower(): returns true if all letters in the string are lowercase and false if not
title(): returns new string with the first letter of each word capitalized ie Hello World
I finished the week by building an employee profile generator! I was surprised I could do it; I was even a little ahead and had to backtrack for the submission to be complete for a few steps. Here are snippets of the Employee Profile Generator!


