Coder Social home page Coder Social logo

seixaserick / dotnet-dns-mx-lookup Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 1.0 218 KB

A native DNS MX query tool for DNS mail record resolver written in C# without package dependencies

License: MIT License

C# 95.82% Dockerfile 4.18%
csharp dns domain-name domains ipv4 ipv6 mail mailservers mxnet sockets

dotnet-dns-mx-lookup's Introduction

C# native DNS MX servers Lookup (no dependencies)

Project Cover

Context

Sometimes we need to check if an email has a valid domain and if this domain has MX records well configured.

This can be used for many proposals such as email validations before form submission, avoiding bounce rates before sending an email to AWS SES, SendGrid or another email provider, cleaning out old database of CRM with primary validation etc.

What does this application do?

  • The app asks what email do you want to verify MX records

  • Then, it runs DNS MX lookup and shows all mail servers with each server preference (priority)

  • Alfer all, asks if you want to run again the app or if you want to quit the program

    Project Cover

Stack and main topics in the project

  • .NET 6.0 console application

    • C#
    • UDP protocol communication
    • Console input, output and cleaning
    • DNS MX protocol standard usage
  • Docker

    • docker build
    • docker run
    • docker container bash interaction (from docker's host shell)

About the Author and license

How to run this project

Clone the repository

If you already installed Git for Windows, run commands below:

git clone https://github.com/seixaserick/dotnet-dns-mx-lookup
cd dotnet-dns-mx-lookup

How to run this project in Docker containers

If you already installed Docker Desktop, just follow these steps below

Creating a docker image

To create a Docker image, run command line below in the command prompt of project directory:

docker build -t dotnet-dns-mx-lookup -f Dockerfile .

Running the app in a docker container

container running

To run the image in Docker container and interact with it, run command line below:

docker run -it --name=dotnet-dns-mx-lookup --restart=unless-stopped dotnet-dns-mx-lookup

To stop the container, run command line below:

docker stop dotnet-dns-mx-lookup

To remove the container (even if it is running), run command line below:

docker rm --force dotnet-dns-mx-lookup

How to build and run without Docker (Windows)

After clone the repository you can open the project with Visual Studio. Build or just debug it pressing F5.

To compile and run it in Windows (Visual Studio required)

Open the solution file dotnet-dns-mx-lookup.sln with your Visual Studio, then press F5 to run the project!

Takeaways

  • DNS protocol uses UPD protocol port 53
  • An email domain my have more than one MX record and you should communicate with high priority servers
  • Dotnet apps (console or not) can run in Linux or Windows OS.
  • Docker is a nice tool to run projects quickly without concern about dependencies and configurations.
  • C# is very similar to other ECMA-based languages (Java, Javascript etc.)
  • Console apps are simple and easy to input and output data.
  • Good Markdown README.md files can help other developers to understand, clone, run and test projects.

Homework challenge

  1. Try to implement a email validation function to return true if an email has at least one valid server domain
  2. Try to sort DNS MX servers list by server preference before print it on console.
  3. Try to check if each DNS server IP is valid and call its TCP 25, 587 or 465 ports (common SMTP ports). Tip: Use native dotnet DNS A record query to find server's IP (IPv4 or IPv6) https://docs.microsoft.com/en-us/dotnet/api/system.net.dns?view=net-6.0
  4. Inspect the code, increase the DNS query timeout and force a network disconnection between one DNS server lookup (unplug your ethernet card and wi-fi) to see what happens. Try to implement an error handling for timeout error. You can simulate primary DNS failing and secondary DNS returning the query (after reconnect your network).
  5. Inspect the Dockerfile content to see how docker pulls imagens from images's hub
  6. Try to create a WebAPI and implement an endpoint to check if an email is valid (https://my-api-server.com/api/[email protected]). You can use this in your website to prevent fake emails (with invalid domains) to contact you by form submmiting.
  7. Try to implement a domain MX records CACHE using native dotnet memory cache or REDIS distributed cache.

dotnet-dns-mx-lookup's People

Contributors

seixaserick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

kang-dol

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.