35
35
"""
36
36
authenticator = IAMAuthenticator (apikey = ibmcloud_api_key )
37
37
38
+
39
+ def setup_logging (default_path = 'logging.json' , default_level = logging .info , env_key = 'LOG_CFG' ):
40
+ """
41
+ Set up logging configuration and use logging.json to format logs
42
+ """
43
+ path = default_path
44
+ value = os .getenv (env_key , None )
45
+ if value :
46
+ path = value
47
+ if os .path .exists (path ):
48
+ with open (path , 'rt' ) as f :
49
+ config = json .load (f )
50
+ logging .config .dictConfig (config )
51
+ else :
52
+ logging .basicConfig (level = default_level )
53
+
54
+
38
55
def sl_iam_client ():
39
56
"""
40
57
Create a SoftLayer client object using the IBM Cloud API key
@@ -47,6 +64,7 @@ def sl_iam_client():
47
64
)
48
65
return client
49
66
67
+
50
68
def get_regions ():
51
69
"""
52
70
Retrieve a list of IBM Cloud VPC regions
@@ -62,6 +80,7 @@ def get_regions():
62
80
logging .error ("Unable to retrieve regions: {0}" .format (e ))
63
81
sys .exit ()
64
82
83
+
65
84
def get_floating_ips ():
66
85
"""
67
86
Retrieve a list of IBM Cloud VPC floating IPs across all regions
@@ -77,6 +96,7 @@ def get_floating_ips():
77
96
floating_ips .append (ip_address )
78
97
return floating_ips
79
98
99
+
80
100
def get_classic_infrastructure_instances ():
81
101
"""
82
102
Retrieve of public IPs associated with classic
@@ -91,6 +111,7 @@ def get_classic_infrastructure_instances():
91
111
classic_host_ips .append (vm ['primaryIpAddress' ])
92
112
return classic_host_ips
93
113
114
+
94
115
def get_classic_infrastructure_hardware ():
95
116
"""
96
117
Retrieve of public IPs associated with classic
@@ -126,6 +147,7 @@ def scan_top_ports(target):
126
147
pass
127
148
return open_ports
128
149
150
+
129
151
def main ():
130
152
"""
131
153
Main function to scan IBM Cloud VPC and classic infrastructure
@@ -154,5 +176,6 @@ def main():
154
176
logging .info (f"Open ports on { target } : { open_ports } " )
155
177
print ("Classic Bare Metals Scan complete." )
156
178
179
+
157
180
if __name__ == "__main__" :
158
181
main ()
0 commit comments