-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from egidijus/build-tools
updated build tools, multiple os/arch support, and only functional output (no more weird bool false print) updated code to work with golang 1.17 (module stuff)
- Loading branch information
Showing
5 changed files
with
217 additions
and
43 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
NAME := showipaddress | ||
PACKAGE_NAME := github.com/egidijus/showipaddress | ||
VERSION := $(shell git describe --tags || echo "unknown-version") | ||
COMMIT := $(shell git rev-parse HEAD) | ||
BUILDTIME := $(shell date -u "+%Y-%m-%d %H:%M:%S %Z") | ||
BUILD_DIR := build | ||
VAR_SETTING := -X "$(PACKAGE_NAME)/constant.Version=$(VERSION)" -X "$(PACKAGE_NAME)/constant.Commit=$(COMMIT)" -X "$(PACKAGE_NAME)/constant.BuildTime=$(BUILDTIME)" | ||
GOBUILD = CGO_ENABLED=0 go build -trimpath -ldflags '-s -w -buildid= $(VAR_SETTING)' \ | ||
-o $(BUILD_DIR) | ||
|
||
PLATFORM_LIST = \ | ||
darwin-amd64 \ | ||
darwin-arm64 \ | ||
linux-amd64 \ | ||
linux-arm64 \ | ||
windows-amd64 \ | ||
windows-arm64 | ||
|
||
|
||
zip_release = $(addsuffix .zip, $(PLATFORM_LIST)) | ||
|
||
|
||
.PHONY: build clean release | ||
normal: clean build | ||
|
||
clean: | ||
@rm -rf $(BUILD_DIR) | ||
@echo "Cleaning up." | ||
|
||
$(zip_release): %.zip : % | ||
@zip -du $(BUILD_DIR)/$(NAME)-$<-$(VERSION).zip -j -m $(BUILD_DIR)/$</$(NAME)* | ||
@zip -du $(BUILD_DIR)/$(NAME)-$<-$(VERSION).zip *.ini | ||
@echo "✅ $(NAME)-$<-$(VERSION).zip" | ||
|
||
all: linux-amd64 darwin-amd64 windows-amd64 linux-arm64 | ||
|
||
all-arch: $(PLATFORM_LIST) | ||
|
||
release: $(zip_release) | ||
|
||
build: | ||
@-mkdir -p $(BUILD_DIR) | ||
$(GOBUILD)/$(NAME) | ||
|
||
darwin-amd64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=amd64 GOOS=darwin $(GOBUILD)/$@/$(NAME) | ||
|
||
darwin-arm64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm64 GOOS=darwin $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-386: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=386 GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-amd64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=amd64 GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-arm: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-armv5: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm GOOS=linux GOARM=5 $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-armv6: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm GOOS=linux GOARM=6 $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-armv7: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm GOOS=linux GOARM=7 $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-arm64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm64 GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-mips-softfloat: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=mips GOMIPS=softfloat GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-mips-hardfloat: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=mips GOMIPS=hardfloat GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-mipsle-softfloat: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=mipsle GOMIPS=softfloat GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-mipsle-hardfloat: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=mipsle GOMIPS=hardfloat GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-mips64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=mips64 GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
linux-mips64le: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=mips64le GOOS=linux $(GOBUILD)/$@/$(NAME) | ||
|
||
freebsd-386: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=386 GOOS=freebsd $(GOBUILD)/$@/$(NAME) | ||
|
||
freebsd-amd64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=amd64 GOOS=freebsd $(GOBUILD)/$@/$(NAME) | ||
|
||
freebsd-arm64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm64 GOOS=freebsd $(GOBUILD)/$@/$(NAME) | ||
|
||
windows-386: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=386 GOOS=windows $(GOBUILD)/$@/$(NAME).exe | ||
|
||
windows-amd64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=amd64 GOOS=windows $(GOBUILD)/$@/$(NAME).exe | ||
|
||
windows-arm: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm GOOS=windows $(GOBUILD)/$@/$(NAME).exe | ||
|
||
windows-armv6: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm GOOS=windows GOARM=6 $(GOBUILD)/$@/$(NAME).exe | ||
|
||
windows-armv7: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm GOOS=windows GOARM=7 $(GOBUILD)/$@/$(NAME).exe | ||
|
||
windows-arm64: | ||
mkdir -p $(BUILD_DIR)/$@ | ||
GOARCH=arm64 GOOS=windows $(GOBUILD)/$@/$(NAME).exe | ||
|
||
|
||
|
||
prep_new_golang: | ||
go mod init github.com/egidijus/showipaddress | ||
go mod tidy |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,34 @@ | ||
# showipaddress | ||
one binary solution to see all IP addresses on a linux machine | ||
|
||
|
||
## What? | ||
one binary solution to see all IP addresses for: | ||
|
||
* linux | ||
* windows | ||
* osx | ||
* bsd | ||
* arm64 | ||
|
||
## How? | ||
|
||
download a release version or build your own with make | ||
|
||
```make all``` | ||
|
||
|
||
simply run the binary produced | ||
|
||
sample output | ||
|
||
``` | ||
./build/linux-amd64/showipaddress | ||
127.0.0.1 | ||
::1 | ||
192.168.1.14 | ||
172.30.0.1 | ||
172.22.0.1 | ||
172.27.0.1 | ||
192.168.49.1 | ||
``` | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/egidijus/showipaddress | ||
|
||
go 1.17 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"net" | ||
"fmt" | ||
"log" | ||
"flag" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net" | ||
) | ||
|
||
|
||
func main() { | ||
boolPtr := flag.Bool("help", false, "single binary ip address show tool, made by Egidijus. https://github.com/egidijus/showipaddress") | ||
flag.Parse() | ||
fmt.Println("help:", *boolPtr) | ||
ifaces, err := net.Interfaces() | ||
if err !=nil { | ||
log.Fatal(err) | ||
} | ||
// handle err | ||
for _, i := range ifaces { | ||
addrs, err := i.Addrs() | ||
if err !=nil { | ||
log.Fatal(err) | ||
} | ||
// handle err | ||
for _, addr := range addrs { | ||
var ip net.IP | ||
switch v := addr.(type) { | ||
case *net.IPNet: | ||
ip = v.IP | ||
fmt.Println(ip) | ||
case *net.IPAddr: | ||
ip = v.IP | ||
fmt.Println(ip) | ||
} | ||
// process IP address | ||
} | ||
} | ||
help_message := "single binary ip address show tool, made by Egidijus. https://github.com/egidijus/showipaddress" | ||
help := flag.Bool("help", false, help_message) | ||
flag.Parse() | ||
if *help { | ||
fmt.Println(help_message) | ||
return | ||
} | ||
ifaces, err := net.Interfaces() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// handle err | ||
for _, i := range ifaces { | ||
addrs, err := i.Addrs() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// handle err | ||
for _, addr := range addrs { | ||
var ip net.IP | ||
switch v := addr.(type) { | ||
case *net.IPNet: | ||
ip = v.IP | ||
fmt.Println(ip) | ||
case *net.IPAddr: | ||
ip = v.IP | ||
fmt.Println(ip) | ||
} | ||
// process IP address | ||
} | ||
} | ||
|
||
} | ||
} |