GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • All gists
  • Back to GitHub
  • Sign in
  • Sign up
  • Code
  • Revisions 9
  • Stars 1
  • Forks 1
  • Terms
  • Privacy
  • Security
  • Status
  • Community
  • Docs

This view

  • Original page
  • New address

GeezerVison is showing gist.github.com — Tinyscript tool for getting IP locations from an email (EML file)

Instantly share code, notes, and snippets.

@dhondta

dhondta/README.md

Last active August 9, 2025 09:11
Show Gist options
  • Download ZIP
  • Star 1 (1) You must be signed in to star a gist
  • Fork 1 (1) You must be signed in to fork a gist
  • Clone this repository at <script src="https://gist.github.com/dhondta/9a8027062ff770b2aa5d8422ddd78b57.js"></script>
  • Save dhondta/9a8027062ff770b2aa5d8422ddd78b57 to your computer and use it in GitHub Desktop.
Clone this repository at <script src="https://gist.github.com/dhondta/9a8027062ff770b2aa5d8422ddd78b57.js"></script>
Save dhondta/9a8027062ff770b2aa5d8422ddd78b57 to your computer and use it in GitHub Desktop.
Download ZIP
Tinyscript tool for getting IP locations from an email (EML file)
Raw
README.md

Get Email Origin

This Tinyscript-based allows to load an email and to parse the receivers, indicating where the found IP addesses originate from.

This can be installed using:

$ pip install ipaddress mail_parser maxminddb-geolite2 tinyscript
$ tsm install get-email-origin
Raw
get-email-origin.py
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import ipaddress
import mailparser
from geolite2 import geolite2
from tinyscript import *
__author__ = "Alexandre D'Hondt"
__version__ = "1.2"
__copyright__ = "A. D'Hondt"
__license__ = "agpl-3.0"
__doc__ = """
This tool loads an email and parses the receivers, indicating where the found IP addesses originate from.
"""
__examples__ = ["message.eml"]
IP_REGEX = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
MMDDB = geolite2.reader()
def parse_eml(eml):
ips = []
found = False
logger.debug("Parsing receivers...")
for receiver in eml.received:
for addr in IP_REGEX.findall(receiver.get('raw', "")):
addr = ipaddress.ip_address(addr)
if str(addr) in ips:
continue
ips.append(str(addr))
logger.debug("Found: {}{}".format(addr, ["", " (private)"][addr.is_private]))
if not addr.is_private:
s, found = str(addr), True
d = MMDDB.get(s)
for f in ["city", "country", "continent"]:
i = d.get(f, {}).get('names', {}).get('en')
if i:
s += "\n{: <9}: {}".format(f.capitalize(), i)
l = d.get('location')
if l:
s += "\nLocation : Lat {} Lon {}".format(l['latitude'], l['longitude'])
try:
s += " ({})".format(l['time_zone'])
except:
pass
logger.info(s)
def valid_eml(filename):
try:
with open(filename) as f:
eml = mailparser.parse_from_file_obj(f)
return eml
except:
raise argparse.ArgumentTypeError
if __name__ == '__main__':
parser.add_argument("eml", type=valid_eml, help="email file")
initialize()
parse_eml(args.eml)
@AnjBat

AnjBat commented Aug 9, 2025

Copy link
Copy Markdown

i don't know how to use

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhondta

dhondta commented Aug 9, 2025

Copy link
Copy Markdown
Author

@AnjBat

$ get-email-origin --help
[...]
usage: get-email-origin [-h] [--help] [-v] eml
[...]
Usage example:
  get-email-origin message.eml

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.