Last active
March 30, 2016 02:53
-
-
Save yeahnoob/f050acbade6fbd589f7a to your computer and use it in GitHub Desktop.
retrieve `netstat.exe` command result in WIN32 system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Get the STY Water Supply Department's IP address | |
package main | |
import ( | |
"bytes" | |
"fmt" | |
"log" | |
"os/exec" | |
"regexp" | |
) | |
func main() { | |
cmd := exec.Command("c:\\WINDOWS\\system32\\netstat.exe", "-n", "-t") | |
var out bytes.Buffer | |
cmd.Stdout = &out | |
err := cmd.Run() | |
if err != nil { | |
log.Fatal(err) | |
} | |
// fmt.Printf("%q\n", out.String()) | |
ipreg := regexp.MustCompile(`\d+\.\d+\.\d+\.\d+`) | |
localreg := regexp.MustCompile(`192\.168\.1\.\d+`) | |
tcpip := ipreg.FindAllString(out.String(), -1) | |
for _, i := range tcpip { | |
if localreg.MatchString(i) { | |
fmt.Println(i) | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment