How to get IP when connected to Wifi on BlackBerry? - blackberry

I'm trying to my application to retrieve the IP address when it's connected to the Wifi network but I'm not too sure how to get that done.
I've looked at RadioInfo and there's a function getIPAddress(int apnId). Is this the right one?
I've also looked at WLANInfo but that one doesn't seem to have any IP related functions.
Anyone can help me with this?

klyubin wrote:
[...] the best solution (as it relies on documented behavior) is to open a udp socket (or TCP server socket) over WiFi and query its IP address. Another hack is to get the APN ID for the "MagicRudyAPN.rim" using getAccessPointNumber, and then query its IP address using getIPAddress. MagicRudyAPN.rim seems to be a virtual/fake APN for accessing/addressing the IP tunnel to the WiFi network.
int apnId = RadioInfo.getAccessPointNumber("MagicRudyAPN.rim");
byte[] ipByte = RadioInfo.getIPAddress(apnId);
String ip = "";
for (int i = 0; i < ipByte.length; i++) {
int temp = (ipByte[i] & 0xff);
if (i < 3)
ip = ip.concat("" + temp + ".");
else {
ip = ip.concat("" + temp);
}
}

Related

Python "scapy": fake ip unable to cheat tcpdump

I use "scapy" to launch SYN flood attack.
Below code generate a fake IP as source IP
The attacker computer's wireshark capture the generated fake IP as source IP, but
the victims computer's tcpdump capture attacker's real IP(NOT the fake IP)
Is scapy unable to cheat tcpdump? or something error with my code?
IP_Packet = IP()
IP_Packet.src = randomIP() #generate a fake IP as source IP
IP_Packet.dst = dstIP
TCP_Packet = TCP()
TCP_Packet.sport = s_port
TCP_Packet.dport = dstPort
TCP_Packet.flags = "S"
TCP_Packet.seq = s_eq
TCP_Packet.window = w_indow
send(IP_Packet / TCP_Packet, verbose=0)
If the victim computer isn't on the same network as the attacker, your router is likely replacing the source IP during the NAT translation. the Victim is receiving the (correct) public IP address, instead of the (spoofed) private IP address

Send data from ESP32 to a server via WiFi

I am not new here but this is my first question.
I have searched a lot and quite frankly can't understand how this is supposed to work.
I get data periodically (temperature) to my ESP32 and while having it set as a WiFi client, connect to my router and somehow store this data on my Laptop(or somewhere else, like a local/web site, don't know if that's possible/better).
How is the connection supposed to work? I have installed XAMPP and run the Apache and MySQL servers and I tried to connect to my Laptop with some sketches from Arduino using the ESP32 libraries
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
const char* host = "192.168.1.109"; //The local IP of my Laptop
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
but it doesn't connect.
Can someone please explain to me how this connection is supposed to take form or is this question too vague? I really just wanna know the "how-things-should-work-together" in this situation.
Thank you in advance.
OK, so after a lot of research and trying, I managed to work it out. I can now send an HTTP request (like GET or POST) from my ESP32 to a local server that is running on my laptop using XAMP and get a response. I can also connect to my local IP from my mobile phone (which is also in the same WiFi network).
Just for anyone else who wants to connect to a location in a server hosted on a PC in a local network, the steps are:
Create a local server on your PC, laptop whatever using an application like XAMPP (I have Windows 10 so WAMP would also work), download, install, open and start Apache.
Make sure that the Firewall lets your requests pass through (for me it was open by default, but I had seen elsewhere Firewall being an issue)
Go to your network settings, select the network that your devices(ESP32, phone, etc.)are connected and change its profile to Private, meaning that you trust this network, making your PC discoverable and able to accept requests. (That is really simple but took me hours to find)
Now, in order to connect from your phone to your PC, open a browser and enter the local IP (that is the IP that is given to your PC from the router as a local network name) of your PC to a browser and that's it, you are connected.
If you installed and ran XAMP, when connecting to your local IP(from same PC or other local device), it will forward you to 192.168.x.x/dashboard. If you want to create new workspaces and files, browse the XAMP folder in the installed location and inside the '/htdocs' subfolder do your testing.
For the ESP32 communication in Arduino(basic steps, not full code):
#include <WiFi.h>
#include <HTTPClient.h>
String host = "http://192.168.x.x/testfolder/";
String file_to_access = "test_post.php";
String URL = host + file_to_access;
void setup(){
WiFi.begin(ssid, password); //Connect to WiFi
HTTPClient http;
bool http_begin = http.begin(URL);
String message_name = "message_sent";
String message_value = "This is the value of a message sent by the ESP32 to local server
via HTTP POST request";
String payload_request = message_name + "=" + message_value; //Combine the name and value
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpResponseCode = http.sendRequest("POST", payload_request);
String payload_response = http.getString();
}
In the test_post.php (located in "C:\xampp\htdocs\testfolder\") file I used a simple script to echo a message received using a POST request, so it's only 'readable' from POST requests. Connecting to it from your browser will give you the "Sorry, accepting..." message.
<?php
$message_received = "";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$message_received = $_POST["message_sent"];
echo "Welcome ESP32, the message you sent me is: " . $message_received;
}
else {
echo "Sorry, accepting only POST requests...";
}
?>
Finally, using Serial prints, the output is:
Response Code: 200
Payload: Welcome ESP32, the message you sent me is: This is the value of a message sent by the ESP32 to local server via HTTP POST request
There it is, hope that this helps someone.

Retrieve IP Address of the Default Printer Driver in UWP

We have a requirement to get the printer IP Address configured in the default printer driver in Control Panel in our UWP app.
I was able to retrieve the "System.DeviceInterface.PrinterPortName" by fetching interface class GUID and passing this above property for retrieval.
But I couldn't get "System.Devices.IpAddress" similarly.
Code pasted below for PortName.
I badly need the IP address as the port name is user's choice and could be modified to any name removing the IP address.
Kindly help sharing working code to retrieve the IP Address using above property or any other way in UWP app.
Below is Working Code for Port Name, Kindly help to fetch IP Address of the same port similarly.
string aqsFilter = "System.Devices.InterfaceClassGuid:=\"{0ecef634-6ef0-472a-8085-5ad023ecbccd}\"";
string[] propertiesToRetrieve = new string[] { "System.DeviceInterface.PrinterPortName"};
DeviceInformationCollection deviceInfoCollection = await DeviceInformation.FindAllAsync(aqsFilter, propertiesToRetrieve);
foreach (DeviceInformation deviceInfo in deviceInfoCollection)
{
if (deviceInfo.IsDefault == true)
{
string strPortName = (string)deviceInfo.Properties["System.DeviceInterface.PrinterPortName"];
if (!string.IsNullOrEmpty(strPortName))
{
strPortName = await ParsePortName(strPortName);
if (!string.IsNullOrEmpty(strPortName))
{
_strIPAddress = strPortName;
}
}
break;
}
}
This is not endorsed because the IP address can change and so it is unreliable.
That being said, if your printer is installed using wsd, it is technically supported
E.g.,
DEVPKEY_PNPX_IpAddress DEVPROP_TYPE_STRING_LIST 32 "10.137.192.202"
But there is no way to reliably use this without a lot of various scenario checks since the IP address may change.
Furthermore, looking at this example, you are not hitting the DAF providers but looking for devices. You are using 0ecef634-6ef0-472a-8085-5ad023ecbccd which is the printer class guid. It also does not look like IP address is propagated in the PnP Explorer property bag so the IP address is not accessible.

IP, MAC & Vlan IDs format

I am working on an ASP.NEt mvc web application, that stores data regarding network devices.but I need to know if there is a global format for these numbers:-
IP address
MAC address
VLanID
subnetmask
And is there any data annotations I can use to implement data validation for these numbers?
Thanks
For IP Address:
IPAddress ip = new IPAddress((long)ips);
return ip.ToString();
To store IP address, read this
For MacAddress, i dont know any existing formats. but you can take it from string.
string macAddStr = "00E0EE00EE00";
string macAddStrNew = macAddStr;
int insertedCount = 0;
for(int i = 2; i < macAddStr.Length; i=i+2)
macAddStrNew = macAddStrNew.Insert(i+insertedCount++, ":");

Get the list of hostnames connected in LAN for Windows Store Apps

I actually tried with the following code, which gave me a result of the local machine Ip address, name and the server Ip address
var hostNamesList = NetworkInformation.GetHostNames();
HostName serverHost = new HostName("cptdomain.ctl.local");
StreamSocket clientSocket = new Windows.Networking.Sockets.StreamSocket();
// Try to connect to the remote host
await clientSocket.ConnectAsync(serverHost, "http");
foreach (var entry in hostNamesList)
{
if (entry.Type == HostNameType.DomainName)
{
hostName.Text = "Machine Name : " + entry.DisplayName;
IPAddress.Text = "Machine IP : " + clientSocket.Information.LocalAddress.DisplayName;
ServerAddress.Text = "Server IP : " + clientSocket.Information.RemoteAddress.DisplayName;
}
}
}
But actually my requirement is, how to get the list of IP addresses and name of the computers that are connected to the server in LAN for Windows Store Apps.
Please guide me in this to get the proper solution for running my store app.
Note: Here I was working with windows8 store apps with WinRT
This is how you do it in a full fat c# application, but I don't think you can do this on a winrt application. At a minimum you will have to add the private network privilege.

Resources