Example #1
0
// 筛选在线的代理IP
func (self *Proxy) findOnline() *Proxy {
	log.Printf(" *     正在筛选在线的代理IP……")
	self.online = 0
	for proxy := range self.all {
		self.threadPool <- true
		go func(proxy string) {
			alive, _, _ := ping.Ping(self.allIps[proxy], CONN_TIMEOUT)
			self.Lock()
			self.all[proxy] = alive
			self.Unlock()
			if alive {
				self.online++
			}
			<-self.threadPool
		}(proxy)
	}
	for len(self.threadPool) > 0 {
		runtime.Gosched()
	}
	log.Printf(" *     在线代理IP筛选完成,共计:%v 个\n", self.online)

	return self
}
Example #2
0
func Ping(address string, timeoutSecond int) (alive bool, err error, timedelay time.Duration) {
	return ping.Ping(address, timeoutSecond)
}