Ejemplo n.º 1
0
func cmdPing(router string, param string) (routeros.Reply, error) {

	if !valid.IsIP(param) && !valid.IsDNSName(param) {
		return routeros.Reply{}, errors.New("This is not a hostname or an IP address.")
	}

	res, err := send(router, fmt.Sprintf("/ping %s", param))
	return res, err
}
Ejemplo n.º 2
0
func cmdTracert(router string, param string) (routeros.Reply, error) {

	if !valid.IsIP(param) && !valid.IsDNSName(param) {
		return routeros.Reply{}, errors.New("This is not a hostname or an IP address.")
	}

	res, err := send(router, fmt.Sprintf("/tool traceroute address=%s duration=40 count=3", param))
	return res, err
}
Ejemplo n.º 3
0
func main() {
	fakeIp := "192.168.101.200:0"
	var netTransport = &http.Transport{
		Dial: (func(network, addr string) (net.Conn, error) {
			// Resolve address
			//if the address is an IP
			host, port, err := net.SplitHostPort(addr)
			if err != nil {
				return nil, err
			}
			switch {
			case govalidator.IsIP(host):
				srvConn, err := tproxy.TcpDial(fakeIp, addr)
				if err != nil {
					return nil, err
				}
				return srvConn, nil
			case govalidator.IsDNSName(host):

				ips, err := net.LookupIP(host)
				if err != nil {
					return nil, err
				}
				for i, ip := range ips {
					srvConn, err := tproxy.TcpDial(fakeIp, net.JoinHostPort(ip.String(), port))
					if err != nil {
						fmt.Println(err)
						if i == len(ips) {
							return srvConn, nil
						}
						continue
					}
					fmt.Println("returning a srvconn")
					return srvConn, nil
				}
				srvConn, err := tproxy.TcpDial(fakeIp, addr)
				if err != nil {
					return nil, err
				}
				return srvConn, nil
			}
			return nil, nil
		}),
	}
	client := &http.Client{Transport: netTransport, CheckRedirect: noRedirect}
	resp, err := client.Get("http://www.google.com/")
	if err != nil && resp == nil {
		fmt.Println(err)
		return
	}
	fmt.Println(resp)

}
Ejemplo n.º 4
0
// Split takes an address, of the form "name*domain" and provides the
// constituent elements.
func Split(address string) (name, domain string, err error) {
	parts := strings.Split(address, Separator)

	if len(parts) != 2 {
		err = ErrInvalidAddress
		return
	}

	name = parts[0]
	domain = parts[1]

	if name == "" {
		err = ErrInvalidName
		return
	}

	if !govalidator.IsDNSName(domain) {
		err = ErrInvalidDomain
		return
	}

	return
}