DHCP Server to Redirect any url to landing page
You appear to be trying to set up what's known as a captive portal.
There are several components to this, one of which is indeed a DHCP server, but that's hardly the most critical one.
A short overview
Your network will have at the very least the following components:
- DHCP server
- DNS server
- Gateway
- A login system
Clients will get an IP address from the DHCP server and will be told to use your DNS server and gateway.
Solution 1: DNS based redirection
Until users are logged in your DNS server replies with the IP address of the login web server. Take care to set a very low TTL on the DNS replies. You want to make sure the clients browser re-resolves the IP address after the login.
This will quite likely cause problems for any application other than web browsing on port 80.
Solution 2: TCP interception
This is a slightly harder solution, but is likely to work better.
The DNS server always returns the correct IP address for whatever web site the client is trying to reach.
The gateway will redirect the TCP sessions on port 80 to the login server.
All other packets should get an ICMP error reply (network unreachable for example).
How do I redirect to a page and not get a cached copy of the landing page
I just found a workaround:
I set another cookie after the login operation: "just-logged-in"
Added some javascript to the landing page that checks for the cookie "just-logged-in" and if it finds the cookie after deleting it (to avoid a reload loop) runs location.reload(true)
which reloads the page ignoring the cache.
This results in another redirection but since the first one is read from the cache we have two HTTP requests as we expected.
Redirect a specific IP address to a special page of my homepage with .htaccess
Add a condition to not rewrite when you're already at specialpage:
RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule ^(.*)$ /specialpage.php [R,L]
Redirect domain name mapped with external IP (modem) to a host in its local network
If you want to redirect my domain to the particular host you need to setup NAT-Virtual Server Setup .
here you need to map remote port to internal map.
In above image IP address is my IP of my host and Default address is my router's IP address
Now you have configure NAT in you router as bellow.
in above image server IP is you host IP address.
I am using D-Link router so this Image is according to that if you are using some different router then you might have different view.
After configuring this when you type EXTERNAL_IP:80 your request will be forwarded to application that is running on you host with that port
Redirect website to unknown internal address
So I ended up going with the android app that scans the local subnet for the device. I have an html file on the server called knockknock.html that simply has the text "HELLO". For anyone interested, here's a first rendition of the code I'm using:
/*
* Get the IP and subnet info and start scanning the local subnet
*/
void findServer() {
WifiManager wifi = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
DhcpInfo dhcp = wifi.getDhcpInfo();
if (dhcp == null) {
Log.d(TAG, "No DHCPInfo on WiFi side.");
}
//Get the string verison of the IP/subnet from the int given by WifiManager
final String ip = intToIp(dhcp.ipAddress);
final String mask = intToIp(dhcp.netmask);
//Start the scanner on a separate thread from the UI
Thread thread = new Thread() {
@Override
public void run() {
serverScanner(ip, mask);
}
};
thread.start();
}
/*
* Convert an integer to a human readable format
*/
String intToIp(int i) {
return ( i & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +
((i >> 16 ) & 0xFF) + "." +
((i >> 24 ) & 0xFF ) ;
}
/*
* Scan the given subnet for the server
*/
void serverScanner(String ip, String netmask) {
//Get the first part of the IP
//TODO: Add support for various subnet masks
String iIPv4 = ip.substring(0, ip.lastIndexOf("."));
iIPv4 += ".";
Log.v(TAG, "Current IP Structure: " + iIPv4);
// Loop to scan each address on the local subnet
for (int i = 1; i < 255; i++) {
//Check to see if the server exists
if (checkServer(iIPv4 + i)) {
//It does exist, so let's set the variable and preferences
mServerIP = iIPv4 + i;
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("LastServerIP", mServerIP);
editor.commit();
return; //And we're done here
}
}
}
/*
* Send a request to the server and see if it's alive and what we're looking for
*/
boolean checkServer(String ip) {
BufferedReader inputStream = null;
try {
HttpGet httpget = new HttpGet("http://" + ip + "/knockknock.html");
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 100);
HttpConnectionParams.setSoTimeout(httpParameters, 100);
HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpResponse response;
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
String result = convertStreamToString(instream);
instream.close();
if (result.equals("HELLO\n")) {
return true;
}
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
//No response or not the response we're looking for, so return false
return false;
}
Related Topics
Git- How to Kill Ssh-Agent Properly on Linux
Adding a New System Call in Linux Kernel 3.3
How to Programmatically Set a Permanent Environment Variable in Linux
How to Capture Network Frames in a Kernel Module
Using the Linux Sysfs_Notify Call
Systemd: "Environment" Directive to Set Path
Sched_Fifo Process with Priority of 99 Gets Preempted
How to Prevent Out of Memory (Oom) Freezes on Linux
Writing Memory of the Traced Process
How to Remove Warning About Storing Unencrypted Password After Committing File in Svn
How to Listen for Multiple Tcp Connection Using Nc
Find and Delete Files with Non-Ascii Names
How to Get in Script Whether Valgrind Found Memory Leaks
Compile Programs on Multicore or Distributed System
Accessing Data Appended to an Elf Binary
Convert Animated Gif to Video on Linux Server While Preserving Frame Rate
Effects of Removing All Symbol Table and Relocation Information from an Executable