textsubs

package module
v0.0.0-...-bd0dc3f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2025 License: GPL-3.0 Imports: 6 Imported by: 3

README

Go Reference

textsubs

A simple Golang library to extract subdomains and domains from text (*not URLs!)

Usage
  1. Import this package in your go program
go get github.com/0x4f53/textsubs
  1. Use it in code as usual
...
subdomains := SubdomainsOnly(string(data), true)

for index, sub := subdomains {
    // Rest of the code
}
...
Documentation

Visit https://pkgo.dev/github.com/0x4f53/textsubs to read about the functions and their descriptions

Working

This package uses publicsuffix2, basic regex matching and a few if-else statements to determine if a string containing dots is a subdomain or not. Please note that certain strings like "readme.md" will be marked as valid subdomains due to .md being a valid TLD.


Copyright (c) 2024 Owais Shaikh

Licensed under GNU GPL 3.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BreakFusedItems

func BreakFusedItems(text string) []string
	Returns: a string slice containing subdomains broken if fused
	Example: en.wikipedia.org0x4f.medium.com gives
		[en.wikipedia.org   0x4f.medium.com]
	Inputs:
 	text (string) -> The text to parse

func DomainsOnly

func DomainsOnly(text string, breakFused bool) ([]string, error)
	Returns: only the domains (example.com) as a list of strings
	Inputs:
 	text (string) -> The text to parse
		breakFused (bool) -> try and split fused domains (e.g. 0x4f.inapple.com becomes [0x4f.in apple.com])

func ListIPs

func ListIPs(text string) ([]string, error)
	Returns: only a list of IP addresses as strings, where each octet is from 0 to 255
	Inputs:
 	text (string) -> The text to parse

func Resolve

func Resolve(items []string) []string
	Returns: a list containing only items (subdomains or domains)
			that resolve when pinged (using LookupHost with local DNS settings and waitgroups)
	Example: [0x4f.in play.google.com fakesite123131231.dev] gives
		[0x4f.in play.google.com]
	Inputs:
 	[item1 item2 item3...] ([]string) -> The list of items to resolve

func SubdomainsOnly

func SubdomainsOnly(text string, breakFused bool) ([]string, error)
	Returns: only the subdomains (subdomain.example.com) as a list of strings
	Inputs:
 	text (string) -> The text to parse
		breakFused (bool) -> try and split fused subdomains (e.g. www.0x4f.iniforgot.apple.com becomes [www.0x4f.in iforgot.apple.com])

Types

type SubAndDom

type SubAndDom struct {
	Subdomain string `json:"subdomain"`
	Domain    string `json:"domain"`
}

func SubdomainAndDomainPair

func SubdomainAndDomainPair(text string, keepDomains bool, breakFused bool) ([]SubAndDom, error)
	Returns: a struct containing a subdomain and its domain
	{subdomain: subdomain.example.com, domain: example.com} as a list of a struct of strings
	Inputs:
 	text (string) -> The text to parse
		keepDomains (bool) -> return domain even if domain does not contain a subdomain
		breakFused (bool) -> try and split fused subdomains and domains (e.g. www.0x4f.iniforgot.apple.com becomes [www.0x4f.in iforgot.apple.com])

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳