/// <summary> /// Return the ID of a project giving its name. It's case sensitive /// </summary> /// <param name="projectName">Name of the GNS3 project which ID you plan to get</param> /// <param name="host">IP where the GNS3 server is hosted. "localhost" by default</param> /// <param name="port">Port where the server is hosted. 3080 by default</param> /// <returns>The ID of the project in case it's found. Null otherwise</returns> public static string GetProjectIDByName(string projectName, string host = "localhost", ushort port = 3080) { string id = null; List <Dictionary <string, object> > projects = null; try { projects = GNS3sharp.ExtractDictionary($"http://{host}:{port.ToString()}/v2/projects", "zoom"); } catch {} if (projects != null) { foreach (Dictionary <string, object> project in projects) { if (projectName.Equals(project["name"].ToString())) { id = project["project_id"].ToString(); break; } } } return(id); }
// Awake is always called before any Start function void Awake() { if (Instance == null) { Instance = this; // If you want to use a GNS3 located on the local machine /* * this.projectHandler = new GNS3sharp.GNS3sharp( * GNS3sharp.ServerProjects.GetProjectIDByName("GameNet") * ); */ // If you use another machine with IP 192.168.1.157 this.projectHandler = new GNS3sharp.GNS3sharp( ServerProjects.GetProjectIDByName("GameNet", host: "192.168.1.157"), _host: "192.168.1.157" ); } else if (Instance != this) { Destroy(gameObject); } }