Skip to content

Commit

Permalink
ip validation along with cname validation
Browse files Browse the repository at this point in the history
  • Loading branch information
chandanpasunoori committed Nov 6, 2022
1 parent aca1e41 commit 917b2c4
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ deployment.yaml
cronjob.yaml
Makefile
bin/
ignored.json
ignored.json
dns-check
Empty file modified .goreleaser.yml
100644 → 100755
Empty file.
Empty file modified Dockerfile
100644 → 100755
Empty file.
Empty file modified cmd/root.go
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions go.mod
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/chandanpasunoori/dns-check

go 1.17
go 1.18

require (
github.com/aws/aws-sdk-go v1.41.4
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326
)

require (
Expand All @@ -15,6 +16,6 @@ require (
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/sys v0.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE=
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -396,8 +398,8 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k=
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
Empty file modified main.go
100644 → 100755
Empty file.
Empty file modified pkg/checker.go
100644 → 100755
Empty file.
31 changes: 26 additions & 5 deletions pkg/helper.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"fmt"
"net"
"os"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ses"
log "github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)

var logger = log.Logger{
Expand All @@ -22,18 +22,39 @@ var logger = log.Logger{
Level: log.InfoLevel,
}

func (d *Domain) getCNAMERecords() string {
func (d *Domain) getCNAMERecords() []string {
cname, err := net.LookupCNAME(d.Name)
if err != nil {
logger.Errorf("error looking up CNAME for %s: %s", d.Name, err)
return ""
return []string{}
}
return cname
return []string{cname}
}

func (d *Domain) getARecords() []string {
ipList, err := net.LookupIP(d.Name)
if err != nil {
logger.Errorf("error looking up A for %s: %s", d.Name, err)
return []string{}
}

var ipListString []string

for _, ip := range ipList {
ipListString = append(ipListString, ip.String())
}

return ipListString
}

func (d *Domain) Check() bool {

var resolvedTarget []string
resolvedTarget = append(resolvedTarget, d.getARecords()...)
resolvedTarget = append(resolvedTarget, d.getCNAMERecords()...)

for _, t := range d.Target {
if strings.Contains(d.getCNAMERecords(), t) {
if slices.Contains(resolvedTarget, t) {
logger.Println(d.Name, "targets", t)
return true
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package pkg

import "testing"

func TestDomain_Check(t *testing.T) {
tests := []struct {
name string
d *Domain
want bool
}{
{
name: "www.shoppersstop.com",
d: &Domain{
Name: "www.shoppersstop.com",
Target: []string{
"k.sni.global.fastly.net",
"152.199.5.41",
"www-shoppersstop-com-1edf.fast.getn7.io.",
},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.d.Check(); got != tt.want {
t.Errorf("Domain.Check() = %v, want %v", got, tt.want)
}
})
}
}
Empty file modified pkg/jobs.go
100644 → 100755
Empty file.

0 comments on commit 917b2c4

Please sign in to comment.