<commit_before>/*
    REVISION HISTORY
     2 Nov 20 -- I started Networking in Go video from Packtpub, and these little programs were part of its code.
                   I'm using it to combine ipinfo with this code to make one utility.  It will do what ipinfo does
                   if a dotted quartet is input, and it will report the domain name doing a reverse lookup.
                   If a domain name is provided, it will do what nslookup does now, on both linux and windows.
		   Since it's possible for a domain name to begin with a number, I retained the option of specifically setting the
		   ip or host string
     5 Nov 20 -- It's useful to always query ipinfo, even if a domain name is entered.
*/
package main

import (
	"context"
	"flag"
	"fmt"
	"io"
	"net"
	"net/http"
	"os"
	"unicode"
	"unicode/utf8"
)

const LastAltered = "5 Nov 2020"

var ip string
var host string
var ns bool
var mx bool
var txt bool
var cname bool
var URL string

const (
	ipMode = iota
	dnsNameMode
)

var ipDNSstate int

func init() {
	flag.StringVar(&ip, "ip", "", "IP address for DNS operation")
	flag.StringVar(&host, "host", "", "Host address for DNS operation")
	flag.BoolVar(&ns, "ns", false, "Host name server lookup")
	flag.BoolVar(&mx, "mx", false, "Host domain mail server lookup")
	flag.BoolVar(&txt, "txt", false, "Host domain TXT lookup")
	flag.BoolVar(&cname, "cname", false, "Host CNAME lookup")
}

type lsdns struct {
	resolver *net.Resolver
}

func main() {
	flag.Parse()
	ls := newLsdns()

	var arg string
	if ip == "" && host == "" {
		if flag.NArg() == 0 {
			fmt.Println("Usage: ipall [ip dotted quarted] | [domain name string]")
			os.Exit(1)
		}

		arg = flag.Arg(0)
		r, _ := utf8.DecodeRuneInString(arg)
		if unicode.IsDigit(r) {
			ip = arg
		} else {
			host = arg
		}
	}

	switch {
	case ip != "":
		ls.reverseLkp(ip)
		ipinfo(ip)

	case host != "":
		ls.nsLkp(host)
		ls.mxLkp(host)
		if txt {              // very long and not very helpful.
			ls.txtLkp(host)  // I'll not display it by default.
		}
		ls.cnameLkp(host)
		ls.hostLkp(host)

	default:
		fmt.Println("flag ip or host must be provided")
		os.Exit(1)
	}
} // end main

func newLsdns() *lsdns {
	return &lsdns{net.DefaultResolver}
}

func (ls *lsdns) reverseLkp(ip string) error {
	names, err := ls.resolver.LookupAddr(context.Background(), ip)<commit_msg>11/05/2020 07:31:12 PM ipall/ipall.go<commit_after>/*
    REVISION HISTORY
     2 Nov 20 -- I started Networking in Go video from Packtpub, and these little programs were part of its code.
                   I'm using it to combine ipinfo with this code to make one utility.  It will do what ipinfo does
                   if a dotted quartet is input, and it will report the domain name doing a reverse lookup.
                   If a domain name is provided, it will do what nslookup does now, on both linux and windows.
		   Since it's possible for a domain name to begin with a number, I retained the option of specifically setting the
		   ip or host string
     5 Nov 20 -- It's useful to always query ipinfo, even if a domain name is entered.
*/
package main

import (
	"context"
	"flag"
	"fmt"
	"io"
	"net"
	"net/http"
	"os"
	"unicode"
	"unicode/utf8"
)

const LastAltered = "5 Nov 2020"

var ip string
var host string
var ns bool
var mx bool
var txt bool
var cname bool
var URL string

const (
	ipMode = iota
	dnsNameMode
)

var ipDNSstate int

func init() {
	flag.StringVar(&ip, "ip", "", "IP address for DNS operation")
	flag.StringVar(&host, "host", "", "Host address for DNS operation")
	flag.BoolVar(&ns, "ns", false, "Host name server lookup")
	flag.BoolVar(&mx, "mx", false, "Host domain mail server lookup")
	flag.BoolVar(&txt, "txt", false, "Host domain TXT lookup")
	flag.BoolVar(&cname, "cname", false, "Host CNAME lookup")
}

type lsdns struct {
	resolver *net.Resolver
}

func main() {
	flag.Parse()
	ls := newLsdns()

	var arg string
	if ip == "" && host == "" {
		if flag.NArg() == 0 {
			fmt.Println("Usage: ipall [ip dotted quarted] | [domain name string]")
			os.Exit(1)
		}

		arg = flag.Arg(0)
		r, _ := utf8.DecodeRuneInString(arg)
		if unicode.IsDigit(r) {
			ip = arg
		} else {
			host = arg
		}
	}

	fmt.Println()
	fmt.Println(" ipall info tool, last altered", LastAltered)
	fmt.Println()

	switch {
	case ip != "":
		ls.reverseLkp(ip)
		ipinfo(ip)

	case host != "":
		ls.nsLkp(host)
		ls.mxLkp(host)
		if txt {              // very long and not very helpful.
			ls.txtLkp(host)  // I'll not display it by default.
		}
		ls.cnameLkp(host)
		ls.hostLkp(host)

	default:
		fmt.Println("flag ip or host must be provided")
		os.Exit(1)
	}
} // end main

func newLsdns() *lsdns {
	return &lsdns{net.DefaultResolver}
}

func (ls *lsdns) reverseLkp(ip string) error {
	names, err := ls.resolver.LookupAddr(context.Background(), ip)
{'fraction_non_alphanumeric': 0.11721840516343952, 'fraction_numerical': 0.009993753903810118, 'mean_word_length': 3.016722408026756, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6046311', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1671, 'n_words': 605}