surferua

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: Apache-2.0 Imports: 4 Imported by: 7

README

surferua

Logo from uasurfer

Surfer UA

High performance User-Agent generator in Golang.

SurferUA on Sourcegraph


Surfer User-Agent (surferua) is a lightweight Golang package that generate HTTP User-Agent strings with particular attention to device type.

Start

Basic usage

  • Install this package to your $GOPATH with command: go get go.zoe.im/surferua

  • Enjoy it!

Some example code below:

package main

import (
	"go.zoe.im/surferua"

	"fmt"
)

func main() {
	fmt.Println(surferua.New().String())

	// functions depends on your generated inputting data.

	fmt.Println(surferua.NewBot())
	fmt.Println(surferua.NewBotGoogle())
	fmt.Println(surferua.New().Phone().String())
	fmt.Println(surferua.New().Android().String())
	fmt.Println(surferua.New().Desktop().Chrome().String())
}

Add more UA

  • Open the config.yml with any editor you like.
  • Edit the cyaml file as you can image what it do
# You can get all User-Agent from: http://www.webapps-online.com/online-tools/user-agent-strings
# If you want to add UA of some version or change them,
# you just need to edit this file and generate code with `go generate` again.
browsers:
  Firefox:
    engine:
      name: Gecko
    version:
      major: [35, 56]
      minor: [35, 56]
      patch: [0, 3]
  Chrome:
    engine:
      name: AppleWebKit
      version:
        major: [534, 603]
        minor: [35, 56]
    version:
      major: [39, 64]
      minor: 0
      patch: [0, 3000]
  Safari:
    engine:
      name: WebKit
      version:
        major: [534, 603]
        minor: [0, 21]
        patch: [0, 10]
    version:
      major: [5, 11]
      minor: [0, 2]
      patch: [0, 10]
platforms:
  Desktop:
    Linux:
    MacOS:
    Windows:
  Phone:
    iOS:
      version:
        major: [6, 11]
        minor: [0, 3]
        patch: [0, 3]
    Android:
      version:
        major: [4, 8]
        minor: [0, 4]
        patch: [0, 4]
bots: # Auto upper the first letter
  google: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
  bing: Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)
  yahoo: Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
  mj12: Mozilla/5.0 (compatible; MJ12bot/v1.4.5; http://www.majestic12.co.uk/bot.php)
  simplePie: SimplePie/1.3.1 (Feed Parser; http://simplepie.org; Allow like Gecko)
  blex: Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)
  yandex: Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)
  scoutJet: Mozilla/5.0 (compatible; ScoutJet; +http://www.scoutjet.com/)
  duck: DuckDuckBot/1.1; (+http://duckduckgo.com/duckduckbot.html)
  baidu: Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)
  sogou: Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)
  sogouOrin: Sogou Orion spider/3.0( http://www.sogou.com/docs/help/webmasters.htm#07)
  exa: Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Exabot-Thumbnails)
  facebook: facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
  alexa: ia_archiver (+http://www.alexa.com/site/help/webmasters; crawler@alexa.com)
  msn: msnbot/2.0b (+http://search.msn.com/msnbot.htm)
  • go generate or make gen in *nix

TODO

  • Add functional way to create UA factory
  • Add testing

Documentation

Overview

Package surferua is a lightweight and high performance Golang package that generate HTTP User-Agent strings with particular attention to device type.

For a full guide visit https://github.com/jiusanzhou/surferua

Index

Examples

Constants

View Source
const Mozilla = "Mozilla"
View Source
const MozillaWithVersion = "Mozilla/5.0"

Variables

View Source
var VERSION = "0.1.0"

Functions

func NewBot

func NewBot() string

NewBot returns a bot ua randomly

func NewBotAlexa

func NewBotAlexa() string

NewBotAlexa returns full user-agent string of alexa.

func NewBotBaidu

func NewBotBaidu() string

NewBotBaidu returns full user-agent string of baidu.

func NewBotBing

func NewBotBing() string

NewBotBing returns full user-agent string of bing.

func NewBotBlex

func NewBotBlex() string

NewBotBlex returns full user-agent string of blex.

func NewBotDuck

func NewBotDuck() string

NewBotDuck returns full user-agent string of duck.

func NewBotExa

func NewBotExa() string

NewBotExa returns full user-agent string of exa.

func NewBotFacebook

func NewBotFacebook() string

NewBotFacebook returns full user-agent string of facebook.

func NewBotGoogle

func NewBotGoogle() string

NewBotGoogle returns full user-agent string of google.

func NewBotMj12

func NewBotMj12() string

NewBotMj12 returns full user-agent string of mj12.

func NewBotMsn

func NewBotMsn() string

NewBotMsn returns full user-agent string of msn.

func NewBotScoutJet

func NewBotScoutJet() string

NewBotScoutJet returns full user-agent string of scoutJet.

func NewBotSimplePie

func NewBotSimplePie() string

NewBotSimplePie returns full user-agent string of simplePie.

func NewBotSogou

func NewBotSogou() string

NewBotSogou returns full user-agent string of sogou.

func NewBotSogouOrin

func NewBotSogouOrin() string

NewBotSogouOrin returns full user-agent string of sogouOrin.

func NewBotYahoo

func NewBotYahoo() string

NewBotYahoo returns full user-agent string of yahoo.

func NewBotYandex

func NewBotYandex() string

NewBotYandex returns full user-agent string of yandex.

func NewPlatformInfoList

func NewPlatformInfoList(m map[interface{}]interface{}) (types []string, l [][]*PlatformInfo)

func RandStringBytesMaskImpr

func RandStringBytesMaskImpr(n int) string

func RandStringBytesMaskImprSrc

func RandStringBytesMaskImprSrc(n int) string

func Seed

func Seed(seed int64)

Types

type Bot

type Bot struct {
	// The name of bot
	Name string

	// The version of bot
	Version string

	// The url of bot
	URL string
}

Bot Crawler UA strings

func (*Bot) String

func (b *Bot) String() (s string)

String generate strings of UserAgent

type Browser

type Browser struct {
	// The name of the browser.
	Name string

	// The name of the browser's engine.
	Engine Engine

	// The version of the browser.
	Semver Semver
}

Browser is br

func (*Browser) String

func (b *Browser) String() string

type BrowserInfo

type BrowserInfo struct {
	Name        string
	EngineInfo  EngineInfo
	VersionInfo VersionInfo
}

func NewBrowserInfo

func NewBrowserInfo(name string, m interface{}) (bi *BrowserInfo)

func NewBrowserInfoList

func NewBrowserInfoList(m map[interface{}]interface{}) (l []*BrowserInfo)

func (*BrowserInfo) Random

func (bi *BrowserInfo) Random() *Browser

type Endpoint

type Endpoint struct {
	Start int
	End   int
}

type Engine

type Engine struct {
	Name   string
	Semver *Semver
}

func (*Engine) String

func (e *Engine) String() string

type EngineInfo

type EngineInfo struct {
	Name        string
	VersionInfo VersionInfo
}

func NewEngineInfo

func NewEngineInfo(m interface{}) (ei EngineInfo)

func (*EngineInfo) Random

func (ei *EngineInfo) Random() (e *Engine)

type Platform

type Platform struct {
	// Name of the operating system. This is sometimes a shorter version of the
	// operating system name, e.g. "Mac OS X" instead of "Intel Mac OS X"
	Name string

	// Operating system version, e.g. 7 for Windows 7 or 10.8 for Max OS X Mountain Lion
	Semver Semver

	// Comment
	Comment string
}

Represents full information on the operating system extracted from the user agent.

func (*Platform) String

func (p *Platform) String() string

type PlatformInfo

type PlatformInfo struct {
	Name string

	VersionInfo VersionInfo

	// this should be random
	Comment string
}

func NewPlatformInfo

func NewPlatformInfo(name string, m interface{}) (pi *PlatformInfo)

func (*PlatformInfo) Random

func (p *PlatformInfo) Random() *Platform

type PreRelease

type PreRelease string

type Semver

type Semver struct {
	Major      int
	Minor      int
	Patch      int
	PreRelease PreRelease
	Metadata   string
}

func (*Semver) String

func (s *Semver) String(seps ...string) string

type UserAgent

type UserAgent struct {
	// contains filtered or unexported fields
}

func New

func New(keys ...string) (ua *UserAgent)
Example
fmt.Println(New().String())

// functions depends on your generated inputting data.

fmt.Println(NewBot())
fmt.Println(NewBotGoogle())
fmt.Println(New().Phone().String())
fmt.Println(New().Android().String())
fmt.Println(New().Desktop().Chrome().String())

// new function from v0.2
// fmt.Println(New(Browser("Chrome", "50"), "Android"))
Output:

func (*UserAgent) Android

func (ua *UserAgent) Android() *UserAgent

Android returns UA with target: Android

func (*UserAgent) Chrome

func (ua *UserAgent) Chrome() *UserAgent

Chrome returns Specified browser: Chrome

func (*UserAgent) Desktop

func (ua *UserAgent) Desktop() *UserAgent

Desktop returns UA with type: Desktop

func (*UserAgent) Firefox

func (ua *UserAgent) Firefox() *UserAgent

Firefox returns Specified browser: Firefox

func (*UserAgent) IOS

func (ua *UserAgent) IOS() *UserAgent

IOS returns UA with target: iOS

func (*UserAgent) Linux

func (ua *UserAgent) Linux() *UserAgent

Linux returns UA with target: Linux

func (*UserAgent) MacOS

func (ua *UserAgent) MacOS() *UserAgent

MacOS returns UA with target: MacOS

func (*UserAgent) Phone

func (ua *UserAgent) Phone() *UserAgent

Phone returns UA with type: Phone

func (*UserAgent) Safari

func (ua *UserAgent) Safari() *UserAgent

Safari returns Specified browser: Safari

func (*UserAgent) String

func (ua *UserAgent) String() (us string)

func (*UserAgent) Windows

func (ua *UserAgent) Windows() *UserAgent

Windows returns UA with target: Windows

type VersionInfo

type VersionInfo struct {
	Major Endpoint
	Minor Endpoint
	Patch Endpoint
}

func NewVersionInfo

func NewVersionInfo(m interface{}) (vi VersionInfo)

func (*VersionInfo) Random

func (vi *VersionInfo) Random() (s *Semver)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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