testhex.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package main
  2. import (
  3. //"github.com/joaojeronimo/go-crc16"
  4. "bytes"
  5. "encoding/binary"
  6. //"strconv"
  7. "fmt"
  8. "net"
  9. "encoding/hex"
  10. //"strconv"
  11. )
  12. func IntToBytes(data int64) []byte {
  13. bytebuf := bytes.NewBuffer([]byte{})
  14. binary.Write(bytebuf, binary.BigEndian, data)
  15. return bytebuf.Bytes()
  16. }
  17. func ipToHexString(ip string) string {
  18. ipa := net.ParseIP(ip)
  19. p1 := fmt.Sprintf("%X", ipa[12])
  20. if len(p1) == 1 {
  21. p1 = "0" + p1
  22. }
  23. p2 := fmt.Sprintf("%X", ipa[13])
  24. if len(p2) == 1 {
  25. p2 = "0" + p2
  26. }
  27. p3 := fmt.Sprintf("%X", ipa[14])
  28. if len(p3) == 1 {
  29. p3 = "0" + p3
  30. }
  31. p4 := fmt.Sprintf("%X", ipa[15])
  32. if len(p4) == 1 {
  33. p4 = "0" + p4
  34. }
  35. s := fmt.Sprintf("%s%s%s%s", p1, p2, p3, p4)
  36. return s
  37. }
  38. func HexStringToBytes(s string) []byte {
  39. b, _ := hex.DecodeString(s)
  40. return b
  41. }
  42. func main () {
  43. /*str := "C0A8E3D4"
  44. bs := []byte{}
  45. for i:=0 ; i<len(str) ; i=i+2 {
  46. fmt.Println(str[i:i+2])
  47. b, _ := strconv.ParseInt(str[i:i+2], 16, 16)
  48. fmt.Println(b)
  49. bs = append(bs, IntToBytes(b)[0])
  50. }
  51. fmt.Printf("%X", bs)
  52. */
  53. //fmt.Println( crc16.Kermit([]byte("Hello World")) )
  54. //c0a8ae5b
  55. //fmt.Printf( "\n%x\n", HexStringToBytes(ipToHexString("192.168.174.91")))
  56. fmt.Printf( "\n%x\n", HexStringToBytes(ipToHexString("127.0.0.1")))
  57. for i:=0 ; i<100 ; i++ {
  58. fmt.Printf(`snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.16.123456%d i 6
  59. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.16.123456%d i 5
  60. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.15.123456%d s "matrix"
  61. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.2.123456%d i 1
  62. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.5.123456%d i 64
  63. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.4.123456%d i 5
  64. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.6.123456%d i 500
  65. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.17.123456%d s ""
  66. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.3.123456%d x 7f000001
  67. snmpset -v 2c -c 2811 192.168.169.26 .1.3.6.1.4.1.9.9.16.1.1.1.16.123456%d i 1
  68. `,i,i,i,i,i,i,i,i,i,i)
  69. }
  70. }