Files

50 lines
919 B
Go
Raw Permalink Normal View History

2019-07-08 15:44:17 -04:00
package libdetectcloud
2019-02-26 17:03:16 -05:00
import (
"net/http"
)
func detectAWS() string {
2024-02-08 12:48:19 +01:00
v1ResultChan := make(chan bool, 1)
v2ResultChan := make(chan bool, 1)
go func() {
2024-02-08 17:49:31 +01:00
v1ResultChan <- detectAWSIDMSv1()
2024-02-08 12:48:19 +01:00
}()
go func() {
2024-02-08 17:49:31 +01:00
v2ResultChan <- detectAWSIDMSv2()
2024-02-08 12:48:19 +01:00
}()
v1Result, v2Result := <-v1ResultChan, <-v2ResultChan
if v1Result || v2Result {
2019-02-26 17:03:16 -05:00
return "Amazon Web Services"
}
return ""
}
2024-02-08 12:48:19 +01:00
2024-02-08 17:49:31 +01:00
func detectAWSIDMSv1() bool {
2024-02-08 12:48:19 +01:00
resp, err := hc.Get("http://169.254.169.254/latest/")
if err != nil {
return false
}
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
}
2024-02-08 17:49:31 +01:00
func detectAWSIDMSv2() bool {
2024-02-08 12:48:19 +01:00
req, err := http.NewRequest("PUT", "http://169.254.169.254/latest/api/token", nil)
if err != nil {
return false
}
req.Header.Set("X-aws-ec2-metadata-token-ttl-seconds", "21600")
resp, err := hc.Do(req)
if err != nil {
return false
}
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
}