main.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. package main
  3. import (
  4. "demo3/pkg"
  5. "github.com/bougou/go-ipmi"
  6. "go.uber.org/zap"
  7. )
  8. func main() {
  9. pkg.InitLog()
  10. host := "127.0.0.1"
  11. port := 623
  12. username := "admin"
  13. password := "password"
  14. client, err := ipmi.NewClient(host, port, username, password)
  15. // Support local mode client if runs directly on linux
  16. // client, err := ipmi.NewOpenClient()
  17. if err != nil {
  18. zap.S().Infof("err: %v", err)
  19. return
  20. }
  21. // you can optionally open debug switch
  22. // client.WithDebug(true)
  23. // Connect will create an authenticated session for you.
  24. if err := client.Connect(); err != nil {
  25. zap.S().Infof("err: %v", err)
  26. return
  27. }
  28. defer client.Close()
  29. //冷重启
  30. err = client.ColdReset()
  31. //热重启
  32. err = client.WarmReset()
  33. ////将计算机系统关机或关闭电源,将系统置于关机状态
  34. //response, err := client.ChassisControl(ipmi.ChassisControlPowerDown)
  35. //// 将计算机系统开机或上电,将系统置于开机状态
  36. //response, err = client.ChassisControl(ipmi.ChassisControlPowerUp)
  37. //// 将计算机系统关闭电源,然后再上电,将系统置于开机状态
  38. //response, err = client.ChassisControl(ipmi.ChassisControlPowerCycle)
  39. //// 执行硬件重置,可能涉及到主板或其他硬件组件的重启。
  40. //response, err = client.ChassisControl(ipmi.ChassisControlHardwareRest)
  41. //// 执行诊断中断,通常用于触发系统进行自检或诊断操作。
  42. //response, err = client.ChassisControl(ipmi.ChassisControlDiagnosticInterrupt)
  43. //// 执行软关机,通常用于操作系统的软关机。
  44. //response, err = client.ChassisControl(ipmi.ChassisControlSoftShutdown)
  45. //
  46. //// 从软盘启动
  47. //err = client.SetBootParamBootFlags(&ipmi.BOP_BootFlags{
  48. // BootDeviceSelector: 0x01,
  49. //})
  50. //
  51. //if err != nil {
  52. // return
  53. //}
  54. //// 选择通道号等相关参数
  55. //channelNumber := uint8(1)
  56. //// 获取 SOL 配置参数
  57. //_, err = client.SOLInfo(channelNumber)
  58. //if err != nil {
  59. // log.Fatal(err)
  60. //}
  61. //
  62. //_, err = client.SOLActivating()
  63. if err != nil {
  64. zap.S().Infof("err: %v", err)
  65. return
  66. }
  67. }
  68. */
  69. package main
  70. import (
  71. "fmt"
  72. "os"
  73. "path/filepath"
  74. )
  75. import "github.com/pin/tftp/v3"
  76. func getCurrentDir() (string, error) {
  77. // 获取当前程序的路径
  78. exePath, err := os.Executable()
  79. if err != nil {
  80. return "", err
  81. }
  82. // 获取程序所在的目录
  83. dir := filepath.Dir(exePath)
  84. return dir, nil
  85. }
  86. func main() {
  87. c, err := tftp.NewClient("28.0.0.1:69")
  88. if err != nil {
  89. fmt.Printf("Error: %v\n", err)
  90. return
  91. }
  92. wt, err := c.Receive("snp.efi", "octet")
  93. file, err := os.Create("C:\\Users\\lx\\GolandProjects\\demo3\\demo3.2\\ipxe.efi")
  94. // Optionally obtain transfer size before actual data.
  95. if n, ok := wt.(tftp.IncomingTransfer).Size(); ok {
  96. fmt.Printf("Transfer size: %d\n", n)
  97. }
  98. n, err := wt.WriteTo(file)
  99. fmt.Printf("%d bytes received\n", n)
  100. }