How to get another location IP Address in Android? - android

City1 : PG-W1 (IP Pool 1.1.0.0/16)
City2 : PG-W2 (IP Pool 2.2.0.0/16)
If I use Android(PDN Address : 1.1.1.1) in City1,
How do I get the IP(2.2.2.2) of the City2? (Without moving)
I tried to find the associated document but failed.. :_(

Related

Coap server resources discovery

I am using the californium library for coap communication and it is being deployed on the Android platform. I have started coap server in one device and the client is on another device, both are in the same network.
Server code :
Creating a server with below resource
class HelloWorldResource extends CoapResource {
public HelloWorldResource() {
// set resource identifier
super("hello");
// set display name
getAttributes().setTitle("Hello-World Resource");
}
#Override
public void handleGET(CoapExchange exchange) {
// respond to the request
exchange.respond("Hello Android!");
}
}
Client code :
CoapClient coapClient = new CoapClient("coap://localhost/.well-known/core");
try {
Set<WebLink> webLinks = coapClient.discover();
System.out.println(webLinks.size());
} catch (ConnectorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
no output from the above code. I don't know the IP address and I want to communicate with the server. is this the right way or I am missing something?
A "discover" is a special coap request, to discover the resources of a known host.
To discover the host, a mutlicast request may be used, but must be supported by the server.
"localhost" is the address of the device itself. With that, the device will send the discover-request to itself.
I don't know the IP address and I want to communicate with the server.
If you dont't know the address, you might either use a "multicast" request first (requires also preparation on the server side, see MulticastServer Example. That example is more complex, than you will need. But demonstrates the principles as well). Or you need to lookup that address (android: settings -> Connections -> WLAN -> Settings-Icon : there you see your IP-address.
coapClient.discover()
Discovers a "known" server, not the local-network. Replace the localhost with "californium.eclipseprojects.io" and you will get:
</.well-known/core>
</large> Large resource
rt: [block]
sz: [1280]
</large-create> Large resource that can be created using POST method
rt: [block]
</large-post> Handle POST with two-way blockwise transfer
rt: [block]
</large-separate> Large resource
rt: [block]
sz: [1280]
</large-update> Large resource that can be updated using PUT method
rt: [block]
sz: [1280]
</link1> Link test resource
rt: [Type1, Type2]
if: [If1]
</link2> Link test resource
rt: [Type2, Type3]
if: [If2]
</link3> Link test resource
rt: [Type1, Type3]
if: [foo]
</location-query> Perform POST transaction with responses containing several Location-Query options (CON mode)
</multi-format> Resource that exists in different content formats (text/plain utf8 and application/xml)
ct: [0, 41, 50, 60]
</obs> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-large> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-non> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-pumping> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-pumping-non> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-reset>
</path> Hierarchical link description entry
ct: [40]
</path/sub1> Hierarchical link description sub-resource
</path/sub2> Hierarchical link description sub-resource
</path/sub3> Hierarchical link description sub-resource
</query> Resource accepting query parameters
</seg1> Long path resource
</seg1/seg2> Long path resource
</seg1/seg2/seg3> Long path resource
</separate> Resource which cannot be served immediately and which cannot be acknowledged in a piggy-backed way
</shutdown>
</test> Default test resource
</validate> Resource which varies
ct: [0]
sz: [20]
All the received links are relative to the server you send the discover to.

How to get correct IPv6 Ip address?

I am trying to display the ip address of connected networks in android. I am using the following code. But it returns 2 IPv6 ip address. How to find the correct ip address from that?
I am using the following code:
List<LinkAddress> linkAddresses = connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getLinkAddresses();
for (LinkAddress linkAddress : linkAddresses) {
Log.i("","LinkAddress getAddress "+linkAddress.getAddress() + "");
Log.i("","Is IPV6 " + (linkAddress.getAddress() instanceof Inet6Address) +"");
Log.i("","Is IPV4 " + (linkAddress.getAddress() instanceof Inet4Address) +"");
Log.i("","Is isLinkLocalAddress " + (linkAddress.getAddress().isLinkLocalAddress()) +"");
Log.i("","Is not isLoopbackAddress " + (!linkAddress.getAddress().isLoopbackAddress()) +"");
}
Now I am getting 4 ip addresses.
LinkAddress getAddress /fe80::2d0:caff:fe00:5ad6
LinkAddress getAddress /2401:4900:2305:14e:2d0:caff:fe00:5ad6
LinkAddress getAddress /2401:4900:2305:14e:28e2:5192:e38f:3e9
LinkAddress getAddress /192.168.43.176
I can identify fe80 is Link Local Ip address and 192. is IPv4 address. But I am confused to identify IPV6 address from this. Please help me to find out the IPv6 ip address.
Both IPv6 addresses are valid. It's normal to have multiple addresses per interface. Both are in the same subnet (2401:4900:2305:14e::/64). When you look at the interface ID (the second half of the address) you'll see that one has ..ff:fe.. in the middle. That's a sign that that address is probably derived from the MAC address of the interface. The other address is a temporary address that will change over time to protect the privacy of the user.
But in short: both addresses are completely valid and usable.

Trying to get network device names with reverse dns in Android

I can able to fetch all device ip addresses in Local Area Network with inetaddress class. What I need to do is reverse lookup ip-address and find as device name in network like : "Jimmie's Macbook"
My Code block which able to fetch all IP address over Local Network Range:
private ArrayList<String> scanSubNet(String subnet) {
ArrayList<String> hosts = new ArrayList<>();
InetAddress inetAddress;
for (int i = 1; i <= 255; i++) {
try {
inetAddress = InetAddress.getByName(subnet + String.valueOf(i));
if (inetAddress.isReachable(1000)) {
hosts.add(inetAddress.getHostName());
Log.d(TAG, InetAddress.getByAddress(inetAddress.getAddress()).getHostAddress());
Log.d(TAG, InetAddress.getByAddress(inetAddress.getAddress()).getCanonicalHostName());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return hosts;
}
And i am calling my method as;
ArrayList<String> subnetList = scanSubNet("192.168.1.");ArrayList<String> subnetList = scanSubNet("192.168.1.");
in Log.d(TAG, i am trying to get device name with reverse dns. But both of line gives me output as ip-address ( Not Device-Name as string)
Is there any chance to succeed it ?
Regards,
Onder.
I just do it with fetching MACID and match first 3digits which belongs manufacturers.
https://macvendors.com/ this website also provide api (Post/GET) to resolve MAC Address.
Instead of resolve fullname of MAC, you need to do Handshake peer to peer.
This is probably happening due to router misconfiguration.
Within a LAN, there are no crucial functions that depend on successful reverse DNS lookups, so a misconfiguration of that kind can easily go undetected for a long time.
It is kind of hard to tell what is wrong in your particular case without a lot more information about your LAN, but the first thing that comes to mind is configuring a proper "DNS Suffix" on the router. This is usually found under DHCP settings.

PJSIP VOIP call not connected using SIP2SIP.info server

i am using PJSIP for voice calling. When i used our server, everything fine i.e. call connected, communicate. But when i am using SIP2SIP.INFO server. Registration is OK But Call is not connected. i saw log in SIP2SIP.info there wasn't log of outgoing or incoming call.
so call is not initiate.
char cfg_reg_uri[] = "sip:sip2sip.info";
char cfg_cred_realm[] = "sip2sip.info";
char cfg_cred_scheme[]="digest";
pjsua_acc_config cfg;
pjsua_acc_config_default(&cfg);
cfg.id = pj_str(cfg_id);
cfg.reg_uri = pj_str(cfg_reg_uri);
cfg.cred_count = 1;
cfg.cred_info[0].realm = pj_str(cfg_cred_realm);
cfg.cred_info[0].scheme = pj_str(cfg_cred_scheme);
cfg.cred_info[0].username = pj_str(cfg_cred_username);
cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
cfg.cred_info[0].data = pj_str(cfg_cred_password);
status = pjsua_acc_add(&cfg, PJ_TRUE, &_acc_id);
I noted that we need to use outbound proxy in sip2sip called "proxy.sipthor.net".
but confused how can i used in pjsip code.
please help expert.
If you read the Sip2Sip device configuration page it states that:
" the SIP device must always perform DNS lookups as defined in SIP standard RFC3263 (NAPTR + SRV + A DNS lookups)"
PJSIP supports DNS SRV lookups.
In PJSUA it will only do DNS SRV lookup if you don't provide the port number in the SIP URL.
"sip:xxx#sip2sip.info" will try to do a DNS SRV record lookup first then fail over to DNS A/C name lookup.
and
"sip:xxx#sip2sip.info:5060" will only do DNS A/C name lookup.
What PJSUA will not support automatically is failover support, they say:
"What we've been suggesting is to implement the failover mechanism in the application layer."
If you want a "quick and easy" setup, what you want to do is set the outbound_proxy to "proxy.sipthor.net". e.g.
cfg.outbound_proxy_cnt = 1;
cfg.outbound_proxy[0] = pj_str("sip:proxy.sipthor.net:5060");
If you want a more robust solution, you need to use pjsip's SRV resolution functions to resolve sip2sip.info srv record e.g: "_sip._udp.sip2sip.info" and then set the outbound_proxy records with the result.
The code is a little bit involved.
pjsip_resolver_t* resolver_;
...
status = pjsip_resolver_create( pool, &resolver_ );
...
pjsip_host_info host;
host.flag = PJSIP_TRANSPORT_DATAGRAM; // is using UDP, see pjsip_transport_flags_e
host.type = PJSIP_TRANSPORT_UDP; // if using UDP, see pjsip_transport_type_e
host.addr.host = pj_str("sip2sip.info");
host.addr.port = 5060;
pjsip_resolve(resolver_, pool, &host, token, resolver_cb_func);
...
static void resolver_cb_func( pj_status_t status, void *token, const struct pjsip_server_addresses *addr)
{
...
// use results to fill in the outbound_proxy
}
You could also take it further to support failover, but it looks like sip2sip doesn't have multiple sip servers in there DNS SRV record so it will not be used currently. If they ever add more then it would become more useful.
_sip._udp.sip2sip.info
Server: fritz.box Address: fd00::2665:11ff:fef9:ec51
Non-authoritative answer:
_sip._udp.sip2sip.info SRV service location:
priority = 100
weight = 100
port = 5060
svr hostname = proxy.sipthor.net
sip2sip.info nameserver = ns2.dns-hosting.info
sip2sip.info nameserver = ns1.dns-hosting.info
sip2sip.info nameserver = ns7.dns-hosting.info
Sip2Sip also support STUN setup, so I would also setup the STUN settings on the account as well:
cfg.stun_srv_cnt = 1;
cfg.stun_srv[0] = pj_str("sip2sip.info");
Since your example seems to not provide the port information it should work. To diagnose this further would require see the pjsip log output.

Finding location using MCC, MNC, LAC, and Cell ID

I know what the values are for MCC, MNC, LAC, & Cell ID. I want to in C write a program to calculate the position in the form of latitude and longitude values in Linux.
FYI:
MCC - Mobile Country Code
MNC - Mobile Network Code
LAC - Location Area Code; a 16 bit number thereby allowing 65536 location areas within one GSM PLMN
more info is available here on Wikipedia, Location Area Identity
Question:
How can I convert MCC,MNC,LAC,Cell ID into latitude and longitude values in linux?
Why does Cell ID varies every time,when trying to read?
To answer your questions:
You can access public databases from terminal or a browser to convert cell ID to lat/lon. Databases include:
Unwired Labs API
OpenCellID
Cell ID is the ID of the cell phone tower your phone/device is connected to. The moment you move a bit, or the signal of another tower nearby is better than the current one, your phone will switch over to that tower, and your Cell ID now reflects the ID of that tower.
i wrote a python script that can do this for you. You can get a binary from the pyc file.
#!/bin/python
"""
Written by Atissonoun - Credits to MFC & HAC
***You need to initialize the script in order to fix the import and the dependency.
This is only a Beta version of the project***
This python file works as the engine for the project.
imports, coordinates, run......
"""
#Importing modules
import requests
#defining a Api_Keys
Google_API_KEY="Your google API Key goes here"
OpenCell_Api_Key ="Your OpenCellID API Key goes here"
def Google(MMC,MNC,LAC,ID,API_KEY=Google_API_KEY):
url = "https://www.googleapis.com/geolocation/v1/geolocate?key={}".format(API_KEY)
data={
"radioType": "gsm",
"cellTowers":[
{
"cellId": ID,
"locationAreaCode": LAC,
"mobileCountryCode": MMC,
"mobileNetworkCode": MNC
}
]
}
response = requests.post(url, json=data)
if response.status_code == 200 :
lat=response.json()[u'location'][u'lat']
long = response.json()[u'location'][u'lng']
d={'LAT':lat,'LONG':long}
print('Located Cell: {}'.format(ID))
return d
else:
print('Error: {}'.format(response.status_code))
return None
def Opencell(MMC,MNC,LAC,ID,API_KEY=OpenCell_Api_Key):
url = "https://us1.unwiredlabs.com/v2/process.php"
data = {
"token": API_KEY,
"radio": "gsm",
"mcc": MMC,
"mnc": MNC,
"cells": [{
"lac": LAC,
"cid": ID
}]
}
response = requests.post(url, json=data)
if response.status_code == 200:
if response.json()[u'status']== 'error':
print('Error: {}'.format(response.json()[u'message']))
return None
else:
lat = response.json()[u'lat']
long = response.json()[u'lon']
d = {'LAT': lat, 'LONG': long}
print('Located Cell: {}'.format(ID))
return d
else:
print('Error: {}'.format(response.status_code))
return None
You either need a database
OpenCellID (they provide APIs for new cell measurement, get the position of a specific cell, etc)
or
use the "secret" API:
"http://www.google.com/glm/mmap" is a non-public API to convert cellLocation to latitude and longitude.
Many ways to do that are given in the answwers for this SO question.
You can use this simple but efficient web site that doesn't need any log in:
http://www.cell2gps.com/
while you can access to operator info like MCC and MNC to the wiki page:
http://en.wikipedia.org/wiki/Mobile_country_code#I
The result is the location GPS through Google Maps,

Categories

Resources