mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2025-02-20 13:02:36 +01:00
linux raw ip support
This commit is contained in:
parent
dd548a4206
commit
c24e1fb24e
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// Temporary class for the sake of not getting nullpointers on linux&mac until they have an IpMapper as well
|
||||
public class EmptyIpMapper implements IpMapper {
|
||||
public class EmptyIpMapper extends IpMapper {
|
||||
@Override
|
||||
public void enable() {
|
||||
|
||||
|
@ -1,16 +1,27 @@
|
||||
package gearth.protocol.hostreplacer.ipmapping;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
// always map to 127.0.0.1, same port
|
||||
public interface IpMapper {
|
||||
public abstract class IpMapper {
|
||||
|
||||
void enable();
|
||||
void runCommand(String... args) {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||
processBuilder.command(args);
|
||||
try {
|
||||
processBuilder.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void addMapping(String ip);
|
||||
abstract public void enable();
|
||||
|
||||
void deleteMapping(String ip);
|
||||
abstract public void addMapping(String ip);
|
||||
|
||||
List<String> getCurrentMappings();
|
||||
abstract public void deleteMapping(String ip);
|
||||
|
||||
abstract public List<String> getCurrentMappings();
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ public class IpMapperFactory {
|
||||
public static IpMapper get() {
|
||||
|
||||
if (OSValidator.isWindows()) return new WindowsIpMapper();
|
||||
if (OSValidator.isUnix()) return new LinuxIpMapper();
|
||||
|
||||
return new EmptyIpMapper();
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package gearth.protocol.hostreplacer.ipmapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LinuxIpMapper extends IpMapper {
|
||||
@Override
|
||||
public void enable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMapping(String ip) {
|
||||
runCommand("iptables", "-t", "nat", "-A", "OUTPUT",
|
||||
"-p", "all", "-d", ip, "-j", "DNAT", "--to-destination", "127.0.0.1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMapping(String ip) {
|
||||
runCommand("iptables", "-t", "nat", "-D", "OUTPUT",
|
||||
"-p", "all", "-d", ip, "-j", "DNAT", "--to-destination", "127.0.0.1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCurrentMappings() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -4,17 +4,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WindowsIpMapper implements IpMapper {
|
||||
|
||||
private void runCommand(String... args) {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||
processBuilder.command(args);
|
||||
try {
|
||||
processBuilder.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public class WindowsIpMapper extends IpMapper {
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user