当前位置: 首页 > news >正文

怎么做一个单页的网站东丰在线网站建设

怎么做一个单页的网站,东丰在线网站建设,湖州建设网站制作,网页传奇哪个最好玩熟悉报文结构 ICMP校验和算法#xff1a; 报文内容#xff0c;相邻两个字节拼接到一起组成一个16bit数#xff0c;将这些数累加求和若长度为奇数#xff0c;则将剩余一个字节#xff0c;也累加求和得出总和之后#xff0c;将和值的高16位与低16位不断求和#xff0c;直…熟悉报文结构 ICMP校验和算法 报文内容相邻两个字节拼接到一起组成一个16bit数将这些数累加求和若长度为奇数则将剩余一个字节也累加求和得出总和之后将和值的高16位与低16位不断求和直到高16位为0以上三步得出结果后取反即为验证和 我们选取实现其中的 先实现命令行部分 var (timeout int64size intcount int )func getCommandArgs() {//通过flag.来读命令行的参数flag.Int64Var(timeout, w, 1000, 请求超时时长单位毫秒)flag.IntVar(size, l, 32, 请求发送缓冲区大小单位字节)flag.IntVar(count, n, 4, 发送请求数)flag.Parse()} func main() {getCommandArgs()fmt.Println(timeout, size, count) } 测试显示可以成功拿到命令行的参数 定义ICMP报文格式 type ICMP struct{Type uint8Code uint8Checksum uint16ID uint16SequenceNum uint16 }全部代码加注释 package mainimport (bytesencoding/binaryflagfmtlognetostime )// 定义全局变量 var (timeout int64 // 请求超时时长单位毫秒size int // 请求发送缓冲区大小单位字节count int // 发送请求数typ uint8 8 // ICMP请求类型code uint8 0 // ICMP请求代码 )// ICMP结构体定义ICMP请求的数据结构 type ICMP struct {Type uint8Code uint8Checksum uint16ID uint16SequenceNum uint16 }func main() {getCommandArgs() // 获取命令行参数// 取出最后一个参数即目标IP地址desIp : os.Args[len(os.Args)-1]// 建立ICMP连接conn, err : net.DialTimeout(ip:icmp, desIp, time.Duration(timeout)*time.Millisecond)if err ! nil {// 如果连接建立失败直接返回log.Fatal(err)return}defer conn.Close()// 打印Ping信息fmt.Printf( 正在Ping %s [%s] 具有 %d 字节的数据:\n, desIp, conn.RemoteAddr(), size)// 发送ICMP请求并接收响应for i : 0; i count; i {t1 : time.Now() // 记录发送时间icmp : ICMP{Type: typ,Code: code,Checksum: 0,ID: 1,SequenceNum: 1,}// 构造ICMP请求数据data : make([]byte, size)var buffer bytes.Bufferbinary.Write(buffer, binary.BigEndian, icmp)buffer.Write(data)data buffer.Bytes()// 计算校验和checkSum : checkSum(data)data[2] byte(checkSum 8) // 高位data[3] byte(checkSum 0xff)// 设置超时时间conn.SetDeadline(time.Now().Add(time.Duration(timeout) * time.Millisecond))// 发送ICMP请求n, err : conn.Write(data)if err ! nil {log.Println(err)continue}// 接收ICMP响应buf : make([]byte, 65535)n, err conn.Read(buf)if err ! nil {log.Println(err)continue}ts : time.Since(t1).Milliseconds() // 计算响应时间fmt.Printf(来自 %d.%d.%d.%d 的回复: 字节%d 时间%dms TTL%d\n, buf[12], buf[13], buf[14], buf[15], n-28, ts, buf[8])time.Sleep(time.Second) // 等待1秒再次发送} }// getCommandArgs函数用于解析命令行参数 func getCommandArgs() {flag.Int64Var(timeout, w, 1000, 请求超时时长单位毫秒)flag.IntVar(size, l, 32, 请求发送缓冲区大小单位字节)flag.IntVar(count, n, 4, 发送请求数)flag.Parse() }// checkSum函数用于计算ICMP请求的校验和 func checkSum(data []byte) uint16 {length : len(data)index : 0var sum uint32 0for length 1 {sum uint32(data[index])8 uint32(data[index1])length - 2index 2}if length ! 0 {sum uint32(data[index])}hi16 : (sum 16)for hi16 ! 0 {sum hi16 uint32(uint16(sum))hi16 (sum 16)}return uint16(^sum) } 好好看 记住运行时需要以管理员身份才能解析socket 使用 go run .\main.go -w 150 -l 32 -n 8 www.baidu.com测试 成功 继续优化 把累计结果加上 package mainimport (bytesencoding/binaryflagfmtlogmathnetostime )// 定义全局变量 var (timeout int64 // 请求超时时长单位毫秒size int // 请求发送缓冲区大小单位字节count int // 发送请求数typ uint8 8 // ICMP请求类型code uint8 0 // ICMP请求代码sendCount intsuccessCount intfailCount intminTs int64 math.MaxInt64maxTs int64totalTs int64 )// ICMP结构体定义ICMP请求的数据结构 type ICMP struct {Type uint8Code uint8Checksum uint16ID uint16SequenceNum uint16 }func main() {getCommandArgs() // 获取命令行参数// 取出最后一个参数即目标IP地址desIp : os.Args[len(os.Args)-1]// 建立ICMP连接conn, err : net.DialTimeout(ip:icmp, desIp, time.Duration(timeout)*time.Millisecond)if err ! nil {// 如果连接建立失败直接返回log.Fatal(err)return}defer conn.Close()// 打印Ping信息fmt.Printf( 正在Ping %s [%s] 具有 %d 字节的数据:\n, desIp, conn.RemoteAddr(), size)// 发送ICMP请求并接收响应for i : 0; i count; i {sendCountt1 : time.Now() // 记录发送时间icmp : ICMP{Type: typ,Code: code,Checksum: 0,ID: 1,SequenceNum: 1,}// 构造ICMP请求数据data : make([]byte, size)var buffer bytes.Bufferbinary.Write(buffer, binary.BigEndian, icmp)buffer.Write(data)data buffer.Bytes()// 计算校验和checkSum : checkSum(data)data[2] byte(checkSum 8) // 高位data[3] byte(checkSum 0xff)// 设置超时时间conn.SetDeadline(time.Now().Add(time.Duration(timeout) * time.Millisecond))// 发送ICMP请求n, err : conn.Write(data)if err ! nil {failCountlog.Println(err)continue}// 接收ICMP响应buf : make([]byte, 65535)n, err conn.Read(buf)if err ! nil {failCountlog.Println(err)continue}successCountts : time.Since(t1).Milliseconds() // 计算响应时间if minTs ts {minTs ts}if maxTs ts {maxTs ts}totalTs tsfmt.Printf(来自 %d.%d.%d.%d 的回复: 字节%d 时间%dms TTL%d\n, buf[12], buf[13], buf[14], buf[15], n-28, ts, buf[8])time.Sleep(time.Second) // 等待1秒再次发送}//统计信息fmt.Printf(%s 的 Ping 统计信息:\n数据包: 已发送 %d已接收 %d丢失 %d (%.2f%% 丢失)\n往返行程的估计时间(以毫秒为单位):\n最短 %dms最长 %dms平均 %dms,conn.RemoteAddr(), sendCount, successCount, failCount, float64(failCount)/float64(sendCount)*100, minTs, maxTs, totalTs/int64(sendCount))}// getCommandArgs函数用于解析命令行参数 func getCommandArgs() {flag.Int64Var(timeout, w, 1000, 请求超时时长单位毫秒)flag.IntVar(size, l, 32, 请求发送缓冲区大小单位字节)flag.IntVar(count, n, 4, 发送请求数)flag.Parse() }// checkSum函数用于计算ICMP请求的校验和 func checkSum(data []byte) uint16 {length : len(data)index : 0var sum uint32 0for length 1 {sum uint32(data[index])8 uint32(data[index1])length - 2index 2}if length ! 0 {sum uint32(data[index])}hi16 : (sum 16)for hi16 ! 0 {sum hi16 uint32(uint16(sum))hi16 (sum 16)}return uint16(^sum) } 成功
http://www.w-s-a.com/news/312260/

相关文章:

  • 个人网站建设论文中期报告申报网站建设理由 模板
  • 岫岩做网站软件开发和app开发的区别
  • 邯郸质量一站式服务平台上线如何做国外销售网站
  • 内蒙古工程建设协会网站sem优化策略
  • Linux网站建设总结建设电子商务平台
  • 公司网站背景图片课程网站如何建设
  • 用js做简单的网站页面互联网技术对人力资源管理的影响有哪些
  • 银川做网站贵德县wap网站建设公司
  • 深圳网站建设zvge山西省煤炭基本建设局网站
  • 佛山网页网站设计线上怎么做推广和宣传
  • 多个域名绑定同一个网站案例
  • 建设网站都需要准备什么代理加盟微信网站建设
  • 网站备案没有了wordpress 添加按钮
  • 湖南建设银行宣传部网站福田蒙派克空调滤芯安装位置图
  • wap网站搜索wordpress工作室模板
  • 青岛金融网站建设如何提交网站地图
  • 制作简单门户网站步骤网站建设论文的摘要
  • 可以直接进入网站的正能量照片学做静态网站
  • 织梦做社交网站合适吗网站的市场如何制作
  • 阳曲网站建设价格多少四川佳和建设工程网站
  • 免费注册店铺位置sem seo什么意思
  • 建筑网站搜图电子商务网站建设渠道
  • 学校网站内容四川手机网站开发
  • 网站制作公司违法商业网站运营成本
  • 显示佣金的网站是怎么做的广告设计主要做哪些
  • 做阿里网站的分录济南seo网站排名关键词优化
  • 北京建设银行纪念钞预定官方网站wordpress中文优化版
  • 宝安做棋牌网站建设找哪家效益快创意设计师个人网站
  • 做线上网站需要多少钱系统开发板价格
  • 建筑企业登录哪个网站wordpress feed地址