diff options
Diffstat (limited to 'verify/ipv6.go')
-rw-r--r-- | verify/ipv6.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/verify/ipv6.go b/verify/ipv6.go new file mode 100644 index 0000000..07ff625 --- /dev/null +++ b/verify/ipv6.go @@ -0,0 +1,73 @@ +package verify + +import ( + "strconv" + + "github.com/sjlleo/netflix-verify/util" +) + +type IPv6Verifier struct { + Config + IP string + unblockStatus int + unblockTestChan chan UnblockTestResult +} + +func (v *IPv6Verifier) Execute() *VerifyResponse { + var err error + var response VerifyResponse + v.unblockStatus = AreaUnavailable + response.Type = 2 + + if v.IP, err = util.DnsResolver(6); err != nil { + response.StatusCode = -2 + return &response + } + + v.unblockTestChan = make(chan UnblockTestResult) + defer close(v.unblockTestChan) + + go v.UnblockTest(AreaAvailableID) + go v.UnblockTest(SelfMadeAvailableID) + go v.UnblockTest(NonSelfMadeAvailableID) + + for i := 0; i < 3; i++ { + switch res := <-v.unblockTestChan; { + + case res.CountryCode != "": + switch res.movieID { + case AreaAvailableID: + v.upgradeStatus(AreaAvailable) + case SelfMadeAvailableID: + v.upgradeStatus(UnblockSelfMadeMovie) + case NonSelfMadeAvailableID: + v.upgradeStatus(UnblockNonSelfMadeMovie) + } + response.CountryCode = res.CountryCode + response.CountryName = util.CountryCodeToCountryName(res.CountryCode) + default: + } + } + response.StatusCode = v.unblockStatus + return &response +} + +func (v *IPv6Verifier) upgradeStatus(status int) { + if v.unblockStatus < status { + v.unblockStatus = status + } +} + +func (v *IPv6Verifier) UnblockTest(MoiveID int) { + + testURL := util.Netflix + strconv.Itoa(MoiveID) + if reCode, err := util.RequestIP(testURL, v.IP, v.LocalAddr); err != nil { + if err.Error() == "Banned" { + v.unblockTestChan <- UnblockTestResult{MoiveID, "", nil} + } else { + v.unblockTestChan <- UnblockTestResult{MoiveID, "", err} + } + } else { + v.unblockTestChan <- UnblockTestResult{MoiveID, reCode, nil} + } +} |