【毕设日记】(4)go语言基于gopacket+fyne简单抓包工具实现之GUI

增加了两个部分的ui和修改app.go的代码
PkgInfo.go 这个是显示下面的16进制原报文数据

package ui
import (
	fyne2 "fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/widget"
	//"github.com/google/gopacket"
)
func loadPkgInfo()  (*fyne2.Container,binding.String){
	bs:=binding.NewString()
	s:=" "
	bs.Set(s)
	l:=widget.NewLabelWithData(bs)
	scrollC:=container.NewVScroll(l)
	speparator:=widget.NewSeparator()
	PkgInfoContainer:=container.NewBorder(nil,speparator,nil,nil,scrollC)
	PkgInfoContainer.Resize(fyne2.NewSize(1600,240))
	return PkgInfoContainer,bs
}
func PkgBytes2String(PkgBytes []byte) string{
	res:=""
	for i,v:=range PkgBytes{
		if i!=0&&i%8==0{
			res+="   "
		}
		if i!=0&&i%16==0{
			res+="\n"
		}
		res+=byte2Hex(v)+" "
	}
	return res
}
func byte2Hex(b byte) string{
	care:=[]string{"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}
	bb:=int(b)
	res:=""
	if b==0{
		return "00"
	}
	if b<16{
		return "0"+care[bb%16]
	}
	for bb>0{
		res=care[bb%16]+res
		bb/=16
	}
	return res
}

Layers.go 这个是显示各层的信息

package ui

import (
	fyne2 "fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/widget"
	//"time"
)
func loadLayers()(*fyne2.Container,binding.String){
	bs:=binding.NewString()
	s:=" "
	bs.Set(s)
	l:=widget.NewLabelWithData(bs)
	scrollC:=container.NewScroll(l)
	speparator:=widget.NewSeparator()
	PkgInfoContainer:=container.NewBorder(nil,speparator,nil,nil,scrollC)
	PkgInfoContainer.Resize(fyne2.NewSize(1600,240))
	return PkgInfoContainer,bs
}

在app.go中修改代码

package ui

import (
	"IP_pkg_analyze/ip"
	fyne2 "fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
)
func Run()  {
	a := app.New()
	//a.Settings().SetTheme(&myTheme{})
	w := a.NewWindow("简单的IP抓包工具")
	appIconPath,err:=fyne2.LoadResourceFromPath("C:\\Users\\Administrator\\Pictures\\QQ截图20190324000505.png")
	if err!=nil{
		panic(err)
	}
	w.SetIcon(appIconPath)
	loadMenus(w)
	//p:=PkgRow{Source: "src",Dest: "dst"}
	b:= ip.Get_if_list()
	Layers,layerinfo:=loadLayers()
	PkgInfo,pkg:=loadPkgInfo()
	PkgList,list:=loadPkgList(layerinfo,pkg)
	PkgListContainer:=container.NewWithoutLayout(PkgList)
	//PkgListContainer.Resize(fyne2.NewSize(1600,280))
	//PkgInfoContainer:=container.NewBorder(PkgListContainer,nil,nil,nil,PkgInfo)
	//PkgInfoContainer.Resize(fyne2.NewSize(1600,280))
	Layers.Move(fyne2.NewPos(0,280))
	PkgInfo.Move(fyne2.NewPos(0,520))
	AllContainer:=container.NewWithoutLayout(PkgListContainer,Layers,PkgInfo)
	w.SetContent(AllContainer)
	w.Resize(fyne2.NewSize(1600, 800))
	go ip.GetPkg(b[0].NPFName,list)
	w.ShowAndRun()
}


结果图:
【毕设日记】(4)go语言基于gopacket+fyne简单抓包工具实现之GUI

上一篇:list操作


下一篇:C语言基础中多次使用scanf问题解决