示例#1
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
}
示例#2
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
}
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)

}
示例#4
0
func (i IsIPChecker) IsFormat(data string) bool {
	return govalidator.IsIP(data)
}
示例#5
0
func (s *service) IsIP(str string) bool                      { return gov.IsIP(str) }