栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

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

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【毕设日记】(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()
}


结果图:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/905975.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号