public async Task <string> GetExternalIpAddress() { var actionName = "GetExternalIPAddress"; var content = GetContent(actionName); var response = await m_httpClient.PostAsync(m_uri, content); var responseContent = await response.Content.ReadAsByteArrayAsync(); var argValue = new XmlSerializable("NewExternalIPAddress"); var argValues = new ServiceArgMap(); argValues.Add(argValue); ParseResponse(responseContent, actionName, argValues); return(argValue.ToXml()); }
public async Task <PortMapping> GetGenericPortMappingEntry(int index) { var actionName = "GetGenericPortMappingEntry"; var args = new ServiceArgMap(); args .Add(new XmlSerializable("NewPortMappingIndex", index)) ; var content = GetContent(actionName, args); var response = await m_httpClient.PostAsync(m_uri, content); var responseContent = await response.Content.ReadAsByteArrayAsync(); var result = new PortMapping(); ParseResponse(responseContent, actionName, new ServiceArgMap().Add(result)); return(result); }
public async Task DeletePortMapping( int externalPort, ProtocolType protocol = ProtocolType.Tcp, string remoteHost = "") { var actionName = "DeletePortMapping"; var args = new ServiceArgMap(); args .Add(new XmlSerializable("NewRemoteHost", remoteHost)) .Add(new XmlSerializable("NewExternalPort", externalPort)) .Add(new XmlSerializable("NewProtocol", ToProtocolName(protocol))) ; var content = GetContent(actionName, args); var response = await m_httpClient.PostAsync(m_uri, content); var responseContent = await response.Content.ReadAsByteArrayAsync(); ParseResponse(responseContent, actionName); }
public async Task AddPortMapping( string internalHost, int internalPort, int externalPort, ProtocolType protocol = ProtocolType.Tcp, string description = null, TimeSpan leaseDuration = new TimeSpan(), bool isEnabled = true, string remoteHost = "") { var actionName = "AddPortMapping"; if (string.IsNullOrEmpty(description)) { description = $"{remoteHost}:{externalPort} -> {internalHost}:{internalPort} via upnp-clr"; } var args = new ServiceArgMap(); args .Add(new XmlSerializable("NewRemoteHost", remoteHost)) .Add(new XmlSerializable("NewExternalPort", externalPort)) .Add(new XmlSerializable("NewProtocol", ToProtocolName(protocol))) .Add(new XmlSerializable("NewInternalPort", internalPort)) .Add(new XmlSerializable("NewInternalClient", internalHost)) .Add(new XmlSerializable("NewEnabled", isEnabled)) .Add(new XmlSerializable("NewPortMappingDescription", description)) .Add(new XmlSerializable("NewLeaseDuration", (int)leaseDuration.TotalSeconds)) ; var content = GetContent(actionName, args); var response = await m_httpClient.PostAsync(m_uri, content); var responseContent = await response.Content.ReadAsByteArrayAsync(); ParseResponse(responseContent, actionName); }