Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package http
- import (
- "log"
- "net/http"
- )
- type NetworkTrafficStruct struct {
- IpAddress string `json:"ip_address"`
- Hostname string `json:"hostname"`
- MacAddress string `json:"mac_address"`
- }
- // Sends an IP Address to the web system
- func SendToWebSystem(ipAddress, hostname, macAddress string) error {
- url := "http://localhost:8000/receive_ip_address"
- //url := "http://192.168.254.155:8000/receive_ip_address"
- resp, err := sendJSONPostRequestToWebSystem(url, ipAddress, hostname, macAddress)
- if err != nil {
- return err
- }
- respBytes, err := readResponseBody(resp)
- if err != nil {
- log.Fatal(err)
- }
- log.Println(string(respBytes))
- return nil
- }
- // Sends a JSON POST request to the Web System's receiving ip_address route
- func sendJSONPostRequestToWebSystem(url, ipAddress, hostname, macAddress string) (*http.Response, error) {
- NetworkTrafficJSON := NetworkTrafficStruct{IpAddress: ipAddress, Hostname: hostname, MacAddress: macAddress}
- log.Println(NetworkTrafficJSON.IpAddress)
- resp, err := sendJSONPostRequest(url, NetworkTrafficJSON)
- if err != nil {
- return nil, err
- }
- return resp, nil
- }
Advertisement
Add Comment
Please, Sign In to add comment