今天写登陆日志遇到了一个问题,就是根据获取到的ip获取地址(调用的百度api )
首先我写了两个工具类
1、这个是用来获取IP地址的(这个ip指的是网络ip,不是本地的ip地址)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import com.zzfeidu.bean.Admin;
@Controller
public class BaseController {
//获取ip地址
public static String getV4IP(){
String ip = "";
String chinaz = "http://ip.chinaz.com";
StringBuilder inputLine = new StringBuilder();
String read = "";
URL url = null;
HttpURLConnection urlConnection = null;
BufferedReader in = null;
try {
url = <