-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.py
More file actions
35 lines (31 loc) · 1.08 KB
/
Copy pathtutorial.py
File metadata and controls
35 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import csv
import requests
import time
from crate import client
import datetime
import os
import subprocess
import docker
#Questa funzione ha lo scopo di ottenere l'indirizzo IP di "docker_web_1", il mio container dove sarà salvato il web_server.
#tale funzione è utile al fine di tenere il mio web server sempre aggiornato sulle possibil variazioni dell'indirizzo IP
command=json.load(os.popen('sudo docker inspect tirociniofiware_web_1'))
print(command)
docker_network=command[0]['HostConfig']['NetworkMode']
print(docker_network)
command=f'sudo docker inspect {docker_network}'
#command=os.popen(command).read()
command=json.load(os.popen(command))
dict_container=command[0]['Containers']
for container in dict_container:
name_container=container
act_cont=dict_container.get(name_container)
if "tirociniofiware_web_1" in act_cont["Name"]:
#print(act_cont["IPv4Address"])
limit=act_cont["IPv4Address"].find('/')
string_use=act_cont["IPv4Address"]
new_string="http://"+string_use[:limit]+":5000"
print(new_string)
f=open("my_ip.txt","w+")
f.write(new_string)
f.close