一个ip、一个发送邮件
来源:8-12 IP获取工具类,发送邮件工具类的引入和代码优化

TimelessPast
2020-10-20
老师您的工具类,获取外网ip 是ipv6 一直是0:0:0:0:0:0:0:1
我找个两个获取ipv4的方法
/**
* 获取公网ipv4地址
* @return
*/
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 = new URL(chinaz);
urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedReader( new InputStreamReader(urlConnection.getInputStream(),"UTF-8"));
while((read=in.readLine())!=null){
inputLine.append(read+"\r\n");
}
//System.out.println(inputLine.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(in!=null){
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Pattern p = Pattern.compile("\\<dd class\\=\"fz24\">(.*?)\\<\\/dd>");
Matcher m = p.matcher(inputLine.toString());
if(m.find()){
String ipstr = m.group(1);
ip = ipstr;
//System.out.println(ipstr);
}
return ip;
}
/**
* 调用cmd,查询内网ipv4ip
* @return
*/
public static String getLocalIPForCMD(){
StringBuilder sb = new StringBuilder();
String command = "cmd.exe /c ipconfig | findstr IPv4";
try {
Process p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while((line = br.readLine()) != null){
line = line.substring(line.lastIndexOf(":")+2,line.length());
sb.append(line);
}
br.close();
p.destroy();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
1.请问 setOperatorIp的时候应该调用哪个,您在工作的实际业务中通常设置内网的ipv4还是公网的ipv4
2.请问根据现在的业务,发送邮件,应该在邮件中发送些什么信息,想不出来当前项目需要发送邮件的业务场景
另:测试发送邮件,发送双方都使用qq邮箱,发送方的密码不能用原qq密码,必须使用生成的第三方服务授权码(POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务) ,不然就抛异常了,请问能解决吗,使其使用自身的qq密码就可以
写回答
1回答
-
你好,这里一般都是内部人员操作,因此主要记录的是内网ip,用于在出问题时追查内部来源;后面这个,通常会使用公司的邮箱,很少会使用qq邮箱,同时一般会为业务申请单独的公司邮箱,由于发送业务相关的邮件。要说需要发生邮件的场景,其实很多,但是这个也需要看你们日常工作的方式,以我们自己而言,订单处理失败需要人工介入时我们就会以邮件的形式发出来
00
相似问题