domainsniff.go 672 B

12345678910111213141516171819202122232425262728293031
  1. package domainsniff
  2. /*
  3. Domainsniff
  4. This package contain codes that perform project / domain specific behavior in Zoraxy
  5. If you want Zoraxy to handle a particular domain or open source project in a special way,
  6. you can add the checking logic here.
  7. */
  8. import (
  9. "net"
  10. "time"
  11. )
  12. // Check if the domain is reachable and return err if not reachable
  13. func DomainReachableWithError(domain string) error {
  14. timeout := 1 * time.Second
  15. conn, err := net.DialTimeout("tcp", domain, timeout)
  16. if err != nil {
  17. return err
  18. }
  19. conn.Close()
  20. return nil
  21. }
  22. // Check if domain reachable
  23. func DomainReachable(domain string) bool {
  24. return DomainReachableWithError(domain) == nil
  25. }