Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/yijunjun/route-table

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/yijunjun/route-table

  • v0.0.0-20160321072918-9608fc1e2e44
  • Source
  • Go
  • Socket score

Version published
Created
Source

route-table

golang获取设置window路由表

package main

import (
	"fmt"
	. "github.com/yijunjun/route-table"
)

func main() {
	table, err := NewRouteTable()
	if err != nil {
		panic(err.Error())
	}
	defer table.Close()
	
	rows, err := table.Routes()
	if err != nil {
		panic(err.Error())
	}

	for _, row := range rows {
		fmt.Sprintf(
			"%v--->%v---->%v",
			Inet_ntoa(row.ForwardDest, false),
			Inet_ntoa(row.ForwardMask, false),
			Inet_ntoa(row.ForwardNextHop, false),
		)
	}

	local_ip, err := GetLocalIp()
	if err != nil {
		panic(err.Error())
	}

	local_ip_uint := Inet_aton(local_ip, false)

	for _, row := range rows {
		if row.ForwardNextHop == local_ip_uint {
			// clone存在的路由,防止自定义出错
			// route add 14.215.177.37 mask 255.255.255.255 本地ip
			row.ForwardDest = Inet_aton("14.215.177.37", false)
			row.ForwardMask = Inet_aton("255.255.255.255", false)

			// 需要管理员权限,才能添加成功
			if err := table.AddRoute(row); err != nil {
				t.Error(err.Error())
			}
			break
		}
	}
}

FAQs

Package last updated on 21 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc