I need to use an instance of HttpListener to get a device's Useragent string (along with a few other custom HTTP headers), but I'm bumping into several walls (quite literally).
The first problem, which I'm not going to care about until the second problem is solved, is that HttpListener requires administrator privileges while the rest of my app doesn't.
The second problem is that windows firewall blocks all traffic to my app. This is obviously a big issue. I can't shamelessly ask my users to turn off their firewall (they might not even know how), and I can't add an exception using code. I understand the security implications for granting access to code that accepts commands from the outside world, but it is my only option.
What should I do?
EDIT I should mention that I've tried to listen on port 80 but that didn't work either. I can make the device connect on any port or address that I want to so that's nothing to worry about.
EDIT2
I'm playing with the idea of using a seperate webserver that takes a simple GUID as an argument, stores the HTTP header information in a database and serves it back to my app when requested. This solves both problems by moving all hosting and parsing logic to an entitiy that I control, the client will only need to use HTTP get requests. Does this seem like overkill to anybody?
EDIT3
Right now I've -sort of- solved it by temporarily adding firewall exceptions by calling netsh
Private Const Port As Integer = 55748
Private Shared Sub AddException()
DeleteException() ' to prevent duplicates
Dim netsh As New Process()
Dim arguments As String = "advfirewall firewall add rule name=""MyApp"" dir=in action=allow protocol=TCP localport=" + Port.ToString
netsh.StartInfo.FileName = "netsh"
netsh.StartInfo.Arguments = arguments
netsh.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
netsh.Start()
End Sub
Private Shared Sub DeleteException()
Dim netsh As New Process()
Dim arguments As String = "advfirewall firewall delete rule name=""MyApp"" dir=in protocol=TCP localport=" + Port.ToString
netsh.StartInfo.FileName = "netsh"
netsh.StartInfo.Arguments = arguments
netsh.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
netsh.Start()
End Sub
And my actual calls look like this
Public Shared Function GetDeviceInfo(ByRef device As Dune) As DeviceInfo
Dim info As DeviceInfo
AddException()
' HttpListener magic happens here
DeleteException()
Return info
End Function
This way there will be a temporary hole in the firewall to let me do my work. Still, someone should have a better idea...