Poco HTTPSClient session by IP address - poco

I'm trying to use Poco HTTPS client session to download a site from hostname by specific IP address.
For example, google.com has the following addresses:
173.194.221.113
173.194.221.138
173.194.221.102
173.194.221.139
173.194.221.100
173.194.221.101
I want to get https://google.com via 173.194.221.102
I was trying the following approach:
std::make_unique<HTTPSClientSession>(SecureStreamSocket(SocketAddress(IPAddress("173.194.221.102"), 0), "https://google.com"));
This fails with the exception "Illegal state: Cannot set the port number for an already connected session"
Looking at the Poco source code, the SecureStreamSocket created with this constructor is connected, and the constructor of HTTPSClientSession tries to set the https port(443), and fails to do that with the already connected socket.
Any better way to do that?

Should be something like that:
Poco::Net::initializeSSL();
Poco::Net::HTTPSessionFactory::defaultFactory().registerProtocol("https", new Poco::Net::HTTPSSessionInstantiator);
const Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> certificateHandler(new Poco::Net::AcceptCertificateHandler(false));
const Poco::Net::Context::Ptr context(new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, ""));
Poco::Net::SSLManager::instance().initializeClient(nullptr, certificateHandler, context);
Poco::URI serverUri("your address");
Poco::Net::HTTPClientSession* session = Poco::Net::HTTPSessionFactory::defaultFactory().createClientSession(serverUri);
Hope it helps.

Related

syslog-ng return original value when mapping does not exists

i'm using syslog-ng for collecting json messages and send alarms to slack
there is parameter in json message which contains IP address of router from which I'm receiving the json message and I want to convert IP address to router hostname
i'm using two parsers 1) parse json 2) replace IP address with router hostname:
parser p_json {
json-parser(prefix(".json."));
};
parser p_acd_router {
add-contextual-data(selector("${.json.router_ip}"), database("host_map.csv"), prefix(".meta_router."));
};
until now everything works fine.
Hi,
I'm having the problem when I receive log message from router and I don't have IP_to_Hostname mapping for it in csv file. in this case i just get blank space in syslog message. there is option to return default value if mapping does not exist, but i would prefer to return original value (IP address)
if mapping exists convert IP address to hostname >> works
if mapping does not exist, return original IP address >> don't know how to set it up
is this even supported?
thanks
You can set the default-selector("UNKNOWN") option for add-contextual-data(), and add a record to your CSV file with the ID UNKNOWN, and use the following value when setting .meta_router.hostname: ${.json.router_ip}.
TLDR: templates are supported inside the CSV file as well.
Note: In case your IPs are reverse-resolvable, you can just use the $(dns-resolve-ip) template function instead of maintaining a complete CSV database:
https://github.com/syslog-ng/syslog-ng/pull/3046

Trouble checking virtual server(vps) connection with qt

I want to enter in the program, ip, username and password of a virtual server(vps), and the program checks that the username and password are correct or not.
I used the following code
void MainWindow::test()
{
QLoggingCategory::setFilterRules("qt.network.ssl.warning=false");
QNetworkAccessManager* manager = new QNetworkAccessManager(this);
QUrl url;
url.setHost("xx.xxx.xx.xx");
url.setPort(3389);
url.setUserName("administrator");
url.setPassword("xxxx");
manager->get(QNetworkRequest(url));
connect(manager,&QNetworkAccessManager::finished, this, &MainWindow::connFinished);
}
output:
QNetworkReply::NetworkError(ProtocolUnknownError)
please guide me
If you only want to know, if the host is online:
I would suggest you use connectToHost from QAbstractSocket Class. The RDP-Protocol is based on TCP/UDP according to Wikipedia and listens on 3389 (what you said in the comments.).
If the connection on TCP 3389 is successful, the host is online.
If you want to verify if the host is online and the authentication works you have to implement your own RDP-library such as FreeRDP, because Qt does not provide any core modules for RDP.

How to Retrieve IP address on Meteorjs?

How to Retrieve IP address on Meteorjs?. Any package is there?. Please advise.
Install the http package:
meteor add http
Then use it:
var result = HTTP.get("https://api.ipify.org");
console.log(result.content)
You can use the mizzao:user-status package to get the IP address of user. It is the standard package used to get such information about client-side user connection and status.
Install it with: meteor add mizzao:user-status
Then you can use the UserStatus.connections (in-memory) collection to get information for all connections on the server, in the following fields:
userId: the user id, if the connection is authenticated.
ipAddr:
the remote address of the connection. A user logged in from different places will have one document per connection. (This is the field you need)
One thing, from their documentation on Atmosphere site:
Note that to read client IP addresses properly, you must set the
HTTP_FORWARDED_COUNT environment variable for your app, and make sure
that IP address headers are forwarded for any reverse proxy installed
in front of the app. See the Meteor docs on this for more details.

How to construct a correct HttpRequest in Salesforce

I am developing an application in Salesforce that should communicate with a server to get some data. the server address is like this http://192.168.115.22/.
this is the HttpRequest object i am constructing in my Apex code is :
HttpRequest request = new HttpRequest();
String username = "myLogin", passwd = "myPassword";
String dataUrl = 'sli=on&fli=on&login=' + username + '&password=' + passwd + 'the rest of data';
request.setMethod('POST');
request.setEndpoint('http://192.168.115.22/Services/getLicenses');
request.setHeader('Content-Type','application/x-www-form-urlencoded');
request.setHeader('Content-Length', String.valueOf(dataUrl.length()));
request.setBody(dataUrl);
Http http = new Http();
HttpResponse response = http.send(request);
But the response i am getting contains this error :
The following error was encountered while trying to retrieve the URL: http://192.168.115.22/Licgen/Service/getLicensePackage?
Access Denied.
i don't know what is the problem with the url i am constructing, and when i write the url manually in my navigator i have access to the server.
Any help please.
This issue, in light of having already been added to the whitelist for endpoints, I think has to do with the fact that 192.168 IP addresses denote local IP addresses within a network normally.
It's likely that you can reach it because you're on your network, but Salesforce cannot see your network from the inside. You would need to use something like ngrok.com which allows you to expose a local machine to an outside available IP address.
You can also find out your router's IP address if you are at home, and port forward to your 192.168.115.22 local machine through it to expose it to the outside world, but I've had a much easier time with ngrok.com for easy integration testing with my applications.
Some Information On 192.168 addresses
(Adding this answer because my other answer could legitimately solve someone searching for the same issue above)
This issue may have to do with the fact that Salesforce prevents outside calls to un-authorized endpoints. Fortunately, it is a simple matter of adding an endpoint to the whitelist of authorized outbound connection points.
Under the setup menu option, and then again under teh security menu, there is a menu item called remote site settings. Within this option you'll see a list of sites you are allowed to access from within Salesforce. If your endpoint isn't in the list, add it and you may get a different result.
Please let me know if you have already added this to the whitelist and it is still a problem.

Nancy cannot load with wildcard url reservations

I have a desktop application that is self hosting a NancyFX web server. Being a desktop application there is a requirement that we allow dynamic IP addresses so we have registered the url using the wildcard option with netsh, as so:
netsh http add urlacl url=http://+:1234/ user=Everyone
However when this application is run under a non-administrator account the following exception is thrown.
The Nancy self host was unable to start, as no namespace reservation existed for the provided url(s).
Please either enable UrlReservations.CreateAutomatically on the HostConfiguration provided to
the NancyHost, or create the reservations manually with the (elevated) command(s):
netsh http add urlacl url=http://192.168.1.90:1234/ user=Everyone
I have tried many combinations of wildcard registrations, all with the same result. I also looked at registering the wildcard when loading Nancy, but due to Nancy using Uri types this was not valid.
I was under the assumption that by using the wildcard registration I had registered any ip address to be used. But Nancy seems to need the specific ip address registered.
I would really appreciate if someone could tell my why the wildcard registration will not work with Nancy, or even better, how to make it work with Nancy.
An old question but if anyone runs into this, Nancy SelfHost allows you to create Url reservations automatically using the HostConfiguration object.
The Url is then reserved automatically on startup.
//Nancy configuration
HostConfiguration hostConfig = new HostConfiguration()
{
UrlReservations = new UrlReservations()
{
//create URL reservations automatically
CreateAutomatically = true
}
};
//Uri
Uri uri = new Uri("http://localhost:9999");
using (var host = new NancyHost(hostConfig, uri))
{
host.Start();
Console.WriteLine("Running self-hosted server ...");
Console.WriteLine("Press [Enter] to close the application.");
Console.ReadLine();
}

Resources