123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /*
- package main
- import (
- "demo3/pkg"
- "github.com/bougou/go-ipmi"
- "go.uber.org/zap"
- )
- func main() {
- pkg.InitLog()
- host := "127.0.0.1"
- port := 623
- username := "admin"
- password := "password"
- client, err := ipmi.NewClient(host, port, username, password)
- // Support local model client if runs directly on linux
- // client, err := ipmi.NewOpenClient()
- if err != nil {
- zap.S().Infof("err: %v", err)
- return
- }
- // you can optionally open debug switch
- // client.WithDebug(true)
- // Connect will create an authenticated session for you.
- if err := client.Connect(); err != nil {
- zap.S().Infof("err: %v", err)
- return
- }
- defer client.Close()
- //冷重启
- err = client.ColdReset()
- //热重启
- err = client.WarmReset()
- ////将计算机系统关机或关闭电源,将系统置于关机状态
- //response, err := client.ChassisControl(ipmi.ChassisControlPowerDown)
- //// 将计算机系统开机或上电,将系统置于开机状态
- //response, err = client.ChassisControl(ipmi.ChassisControlPowerUp)
- //// 将计算机系统关闭电源,然后再上电,将系统置于开机状态
- //response, err = client.ChassisControl(ipmi.ChassisControlPowerCycle)
- //// 执行硬件重置,可能涉及到主板或其他硬件组件的重启。
- //response, err = client.ChassisControl(ipmi.ChassisControlHardwareRest)
- //// 执行诊断中断,通常用于触发系统进行自检或诊断操作。
- //response, err = client.ChassisControl(ipmi.ChassisControlDiagnosticInterrupt)
- //// 执行软关机,通常用于操作系统的软关机。
- //response, err = client.ChassisControl(ipmi.ChassisControlSoftShutdown)
- //
- //// 从软盘启动
- //err = client.SetBootParamBootFlags(&ipmi.BOP_BootFlags{
- // BootDeviceSelector: 0x01,
- //})
- //
- //if err != nil {
- // return
- //}
- //// 选择通道号等相关参数
- //channelNumber := uint8(1)
- //// 获取 SOL 配置参数
- //_, err = client.SOLInfo(channelNumber)
- //if err != nil {
- // log.Fatal(err)
- //}
- //
- //_, err = client.SOLActivating()
- if err != nil {
- zap.S().Infof("err: %v", err)
- return
- }
- }
- */
- package main
- import (
- "fmt"
- "os"
- "path/filepath"
- )
- import "github.com/pin/tftp/v3"
- func getCurrentDir() (string, error) {
- // 获取当前程序的路径
- exePath, err := os.Executable()
- if err != nil {
- return "", err
- }
- // 获取程序所在的目录
- dir := filepath.Dir(exePath)
- return dir, nil
- }
- func main() {
- c, err := tftp.NewClient("28.0.0.1:69")
- if err != nil {
- fmt.Printf("Error: %v\n", err)
- return
- }
- wt, err := c.Receive("snp.efi", "octet")
- file, err := os.Create("C:\\Users\\lx\\GolandProjects\\demo3\\demo3.2\\ipxe.efi")
- // Optionally obtain transfer size before actual data.
- if n, ok := wt.(tftp.IncomingTransfer).Size(); ok {
- fmt.Printf("Transfer size: %d\n", n)
- }
- n, err := wt.WriteTo(file)
- fmt.Printf("%d bytes received\n", n)
- }
|