proksi

package module
v0.0.0-...-7f20099 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2014 License: MIT Imports: 8 Imported by: 0

README

proksi GoDoc

A very fast proxy tester

##How-to-use

See example directory for basic example and main.go for function use.

##License

MIT

Documentation

Overview

Example
package main

import (
	"bytes"
	"fmt"
	"github.com/9uuso/proksi"
	"os"
	"path/filepath"
	"time"
)

func main() {

	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	proxychan := make(chan proksi.Proxy)
	lines := 0
	amountOf := 0
	alive := 0
	te := time.Now()
	var timeout = time.Millisecond * 2500
	var buffer bytes.Buffer

	proxies, err := proksi.ReadFile(dir + "/proxies.txt")
	if err != nil {
		fmt.Println(err)
	}

	for _, proxy := range proxies {
		lines++
		amountOf++
		go proksi.ResolveAndWrite(proxychan, proxy, timeout, "http://google.com/")
	}

	for proxy := range proxychan {

		lines--

		if proxy.Alive {
			alive++
			buffer.WriteString(proxy.Address + "\n")
		}

		if lines == 0 {
			err := proksi.WriteFile(dir+"/checked-proxies.txt", buffer)
			if err != nil {
				fmt.Println(err)
			}
			fmt.Println("Checked", amountOf, "proxies in", time.Now().Sub(te), "and of which", alive, "responded.")
		}
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadFile

func ReadFile(filename string) ([]string, error)

ReadFile returns string array of IP addresses in a file. It uses scanner.Scan() to parse IP's from the given file.

func Resolve

func Resolve(status chan Proxy, host string, timeout time.Duration)

Resolve makes TCP connection to given host with given timeout. The function broadcasts to given channel about the response of the connection. Even if the connection is refused or it times out, the channel will receive new proxy instance with filled fields.

func ResolveAndWrite

func ResolveAndWrite(status chan Proxy, host string, timeout time.Duration, endpoint string)

Same as Resolve function, but takes in extra parameter which defines what HTTP site the proxy will attempt to connect with HEAD. The timeout in both TCP and HTTP connections are the same. Useful for checking whether a proxy is busy or not.

func WriteFile

func WriteFile(filename string, buffer bytes.Buffer) error

WriteFile writes given buffer to given filename. It creates the file it is not yet created. The created file uses 0600 permissions by default.

Types

type Proxy

type Proxy struct {
	Alive        bool
	ResponseTime time.Duration
	Address      string
}

Alive stands for boolean whether the proxy responded in Resolve function. ResponseTime is time it took for the instance to respond. Address is (for now) a string representing the IP address of the proxy to be connected.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL