Guest User

Untitled

a guest
Aug 14th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package http
  2.  
  3. import (
  4. "log"
  5. "net/http"
  6. )
  7.  
  8. type NetworkTrafficStruct struct {
  9. IpAddress string `json:"ip_address"`
  10. Hostname string `json:"hostname"`
  11. MacAddress string `json:"mac_address"`
  12. }
  13.  
  14. // Sends an IP Address to the web system
  15. func SendToWebSystem(ipAddress, hostname, macAddress string) error {
  16. url := "http://localhost:8000/receive_ip_address"
  17. //url := "http://192.168.254.155:8000/receive_ip_address"
  18. resp, err := sendJSONPostRequestToWebSystem(url, ipAddress, hostname, macAddress)
  19. if err != nil {
  20. return err
  21. }
  22. respBytes, err := readResponseBody(resp)
  23. if err != nil {
  24. log.Fatal(err)
  25. }
  26. log.Println(string(respBytes))
  27. return nil
  28. }
  29.  
  30. // Sends a JSON POST request to the Web System's receiving ip_address route
  31. func sendJSONPostRequestToWebSystem(url, ipAddress, hostname, macAddress string) (*http.Response, error) {
  32. NetworkTrafficJSON := NetworkTrafficStruct{IpAddress: ipAddress, Hostname: hostname, MacAddress: macAddress}
  33. log.Println(NetworkTrafficJSON.IpAddress)
  34. resp, err := sendJSONPostRequest(url, NetworkTrafficJSON)
  35. if err != nil {
  36. return nil, err
  37. }
  38. return resp, nil
  39. }
Advertisement
Add Comment
Please, Sign In to add comment