- Navigate to the folder
./spam/
that contains all.eml
email files. - Loop through all
.eml
files and read them using theemail
module.
For each email:
- Retrieve the
To:
address. - Check if the address ends with
@find the cyfo inc email
.- If it does, keep the email.
At the end of this stage, you will have a list of emails sent to CYFO INC employees.
For each CYFO INC email:
- Collect all
Received:
headers (there are usually many). - Identify the first sending server:
- The first sending server is found in the last
Received:
header (email headers are reverse chronological). - If the last headers don’t contain IPs (e.g., spam filters), keep popping the last header until you find one with an IPv4 address.
- The first sending server is found in the last
From the valid Received:
header:
- Use a regex to find all IPv4 addresses (e.g.,
192.168.1.1
,34.71.206.167
). - For each IP:
- Use
ipaddress.ip_address()
to validate it. - Skip it if it's a private IP (e.g.,
10.x.x.x
,192.168.x.x
, etc.). - If it’s public, add it to a set of unique IPs.
- Use
- Sort the list of unique public IPs.
- Print the results.