Giter Club home page Giter Club logo

go-procnet's Introduction

Go-ProcNet

A go module for parsing linux socket files, supporting:

  • /proc/net/tcp
  • /proc/net/tcp6
  • /proc/net/udp
  • /proc/net/udp6

Can also be used for socket files of a specific process under /proc/<PID>/net/

Based on the source code of https://github.com/cakturk/go-netstat

Installation:

$ go get github.com/otterize/go-procnet

Usage:

package main

import (
	"fmt"
	"github.com/otterize/go-procnet/procnet"
)

func main() {
	// parsing the tcp sockets from /proc/net/tcp
	socks, err := procnet.TCPSocks()
	if err != nil {
		panic(err)
	}
	for _, sock := range socks {
		fmt.Printf("local ip: %s local port: %d remote IP: %s remote port: %d state: %s",
			sock.LocalAddr.IP, sock.LocalAddr.Port, sock.RemoteAddr.IP, sock.RemoteAddr.Port, sock.State)
	}

	// for parsing the sockets from a custom path
	socks, err = procnet.SocksFromPath("/proc/1234/net/udp")
	// ...

	// for parsing the sockets from the textual content of a socket file
	socks, err = procnet.SocksFromText(` sl  local_address                         remote_address                        st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
	0: 00000000000000000000000000000000:1B58 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 854815644 1 0000000000000000 100 0 0 10 0
	1: 0000000000000000FFFF0000860EA8C0:1B58 0000000000000000FFFF0000E70FA8C0:87F6 01 00000000:00000000 00:00000000 00000000     0        0 854824433 1 0000000000000000 20 4 1 10 -1`)
	// ...
}

go-procnet's People

Contributors

amit7itz avatar cakturk avatar chicknsoup avatar immortalin avatar skaji avatar vitalyisaev2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.