network

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 12 Imported by: 0

README

Network Examples

Download a file from url

package main

import (
  "fmt"
  "log"

  "github.com/D3Ext/maldev/network"
)

func main(){
  err := network.DownloadFile("https://example.com/file.txt") // File saved as filename, in this case file.txt
  if err != nil {
    log.Fatal(err)
  }
}

Get status code of url

package main

import (
  "fmt"
  "log"

  "github.com/D3Ext/maldev/network"
)

func main(){
  code, err := network.GetStatusCode("https://google.com")
  if err != nil {
    log.Fatal(err)
  }

  fmt.Println(code)
}

List all network interfaces

package main

import (
  "fmt"
  "log"

  "github.com/D3Ext/maldev/network"
)

func main(){
  interfaces, err := network.ListAllInterfaces() // func ListAllInterfaces() ([]string, error)
  if err != nil {
    log.Fatal(err)
  }
}

Get all information about an interface

package main

import (
  "fmt"
  "log"

  "github.com/D3Ext/maldev/network"
)

func main(){
  info, err := network.GetInterfaceInfo("wlan0") // func GetInterfaceInfo(interface_name string) (net.Interface, error)
  if err != nil {
    log.Fatal(err)
  }

  fmt.Println(info)
  format := network.FormatInfo(info)
  fmt.Println(format)
}

Check internet connection

package main

import (
  "fmt"

  "github.com/D3Ext/maldev/network"
)

func main(){
  check := network.CheckInternet()
  fmt.Println(check) // true or false
}

List active ports

package main

import (
  "fmt"

  "github.com/D3Ext/maldev/network"
)

func main(){
  raw_netstat := network.Netstat() // func Netstat() ([]*PortsInfo, error)
  fmt.Println(raw_netstat)

  formated_netstat := network.FormatedNetstat() // func FormatedNetstat() (string, error)
  fmt.Println(formated_netstat) // Represented in columns
}

Get public ip

package main

import (
  "fmt"

  "github.com/D3Ext/maldev/network"
)

func main(){
  ip := network.GetPublicIp()
  fmt.Println(ip)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckInternet

func CheckInternet() bool

func DownloadFile

func DownloadFile(file_url string) error

func FormatInfo

func FormatInfo(interface_info net.Interface) string

func FormatedNetstat

func FormatedNetstat() (string, error)

func GetInterfaceInfo

func GetInterfaceInfo(interface_name string) (net.Interface, error)

func GetPublicIp

func GetPublicIp() string

func GetStatusCode

func GetStatusCode(url_to_check string) (int, error)

func ListAllInterfaces

func ListAllInterfaces() ([]string, error)

Types

type IP

type IP struct {
	Query string
}

type PortsInfo

type PortsInfo struct {
	Name  string
	Port  int
	Pid   int
	State netstat.SkState
}

func Netstat

func Netstat() ([]*PortsInfo, error)

Jump to

Keyboard shortcuts

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