java收货地址解析代码 收货地址代码怎么写
求获取客户端mac地址java代码,急需急需,麻烦了
通过ip获取指定ip地址的mac地址,ip可以通过请求request获取,
公司主营业务:成都网站建设、成都做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联公司推出埇桥区免费做网站回馈大家。
request.getRemoteAddr();
(当然获取ip也不是在任何情况下都有效的)
通过了Apache,Squid等反向代理软件就不能获取到客户端的真实IP地址。
您也许需要通过其他的方式获取,(见附)
//获取mac如下 (nbtstat -A IPAddress是对给定的IP地址解析其主机名。如果不能正常解析它的主机
//名的话,有可能是防火墙屏蔽了。也可能是在DNS中将NetBios 解析选项屏蔽了。)
public String getMACAddress(String ip){
String str = "";
String macAddress = "";
try {
Process p = Runtime.getRuntime().exec("nbtstat -A " + ip);
InputStreamReader ir = new InputStreamReader(p.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (int i = 1; i 100; i++) {
str = input.readLine();
if (str != null) {
if (str.indexOf("MAC Address") 1) {
macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
break;
}
if (str.indexOf("MAC Address") 1) {
macAddress = str.substring(str.indexOf("MAC 地址") + 14, str.length());
break;
}
//以上有个判断,不同系统cmd命令执行的返回结果展示方式不一样,我测试的win7是MAC 地址
//所以又第二个if判断 你可先在你机器上cmd测试下nbtstat -A 命令 当然得有一个你可以ping通的
//网络ip地址,然后根据你得到的结果中mac地址显示方式来确定这个循环取值
}
}
} catch (IOException e) {
e.printStackTrace(System.out);
}
return macAddress;
}
附:
通过代理了的客户端ip地址获取方式
于是可得出获得客户端真实IP地址的方法一:
public String getRemortIP(HttpServletRequest request) {
if (request.getHeader("x-forwarded-for") == null) {
return request.getRemoteAddr();
}
return request.getHeader("x-forwarded-for");
}
获得客户端真实IP地址的方法二:
public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
可是,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,究竟哪个才是真正的用户端的真实IP呢?
答案是取X-Forwarded-For中第一个非unknown的有效IP字符串。如:
X-Forwarded-For:192.168.1.110, 192.168.1.120, 192.168.1.130, 192.168.1.100
用户真实IP为: 192.168.1.110
java 解析 eml的源代码
// 从EML文件得到MimeMessage对象
MimeMessage message = new MimeMessage(session, new FileInputStream(emlFile));
public static String getMailSubject(Message message) throws Exception {
return MimeUtility.decodeText(message.getSubject());
}
public static String getMailSender(Message message) throws Exception {
String emailSender = null;
Address[] addresses = message.getFrom();
if (addresses == null || addresses.length 1) {
throw new IllegalArgumentException("该邮件没有发件人");
}
// 获得发件人
InternetAddress address = (InternetAddress) addresses[0];
String senderName = address.getPersonal();
if (senderName != null) {
senderName = MimeUtility.decodeText(senderName);
emailSender = senderName + "" + address.getAddress() + "";
} else {
senderName = address.getAddress();
}
return emailSender;
}
public static String getMailRecipients(Message message, Message.RecipientType recipientType) throws Exception {
StringBuilder builder = new StringBuilder();
Address[] addresses = null;
if (recipientType == null) {
addresses = message.getAllRecipients();
} else {
addresses = message.getRecipients(recipientType);
}
if (addresses == null || addresses.length 1) {
throw new IllegalArgumentException("该邮件没有收件人");
}
for (Address address : addresses) {
InternetAddress iAddress = (InternetAddress) address;
builder.append(iAddress.toUnicodeString()).append(", ");
}
return builder.deleteCharAt(builder.length() - 1).toString();
}
public static String getMailSendDate(Message message, String pattern) throws Exception {
String sendDateString = null;
if (pattern == null || "".equals(pattern.trim())) {
pattern = "yyyy年MM月dd日 E HH:mm";
}
Date sendDate = message.getSentDate();
sendDateString = new SimpleDateFormat(pattern).format(sendDate);
return sendDateString;
}
public static boolean containsAttachment(Part part) throws Exception {
boolean flag = false;
if (part != null) {
if (part.isMimeType("multipart/*")) {
MimeMultipart mp = (MimeMultipart) part.getContent();
for (int i = 0; i mp.getCount(); i++) {
BodyPart bodyPart = mp.getBodyPart(i);
String disposition = bodyPart.getDisposition();
if (disposition != null (Part.ATTACHMENT.equalsIgnoreCase(disposition)
|| Part.INLINE.equalsIgnoreCase(disposition))) {
flag = true;
} else if (bodyPart.isMimeType("multipart/*")) {
flag = containsAttachment(bodyPart);
} else {
String contentType = bodyPart.getContentType();
if (contentType.indexOf("application") != -1) {
flag = true;
}
if (contentType.indexOf("name") != -1) {
flag = true;
}
}
if (flag)
break;
}
} else if (part.isMimeType("message/rfc822")) {
flag = containsAttachment((Part) part.getContent());
}
}
return flag;
}
public static boolean isSeen(Message message) throws Exception {
if (message == null) {
throw new MessagingException("Message is empty");
}
return message.getFlags().contains(Flags.Flag.SEEN);
}
public static boolean isReplaySign(Message message) throws Exception {
if (message == null) {
throw new MessagingException("Message is empty");
}
boolean replaySign = false;
String[] headers = message.getHeader("Disposition-Notification-To");
if (headers != null headers.length 0) {
replaySign = true;
}
return replaySign;
}
public static String getMailPriority(Message message) throws Exception {
if (message == null) {
throw new MessagingException("Message is empty");
}
String priority = "普通";
String[] headers = message.getHeader("X-Priority");
if (headers != null headers.length 0) {
String mailPriority = headers[0];
if (mailPriority.indexOf("1") != -1 || mailPriority.indexOf("High") != -1) {
priority = "紧急";
} else if (mailPriority.indexOf("5") != -1 || mailPriority.indexOf("Low") != -1) {
priority = "低";
} else {
priority = "普通"; // 3或者Normal;
}
}
return priority;
}
public static void getMailTextContent(Part part, StringBuilder content) throws Exception {
if (part == null) {
throw new MessagingException("Message content is empty");
}
boolean containsTextInAttachment = part.getContentType().indexOf("name") 0;
if (part.isMimeType("text/*") containsTextInAttachment) {
content.append(part.getContent().toString());
} else if (part.isMimeType("message/rfc822")) {
getMailTextContent((Part) part.getContent(), content);
} else if (part.isMimeType("multipart/*")) {
Multipart mp = (Multipart) part.getContent();
for (int i = 0; i mp.getCount(); i++) {
BodyPart bodyPart = mp.getBodyPart(i);
getMailTextContent(bodyPart, content);
}
} else if (part.isMimeType("image/*")) {
// TODO part.getInputStream()获得输入流然后输出到指定的目录
} else {
// TODO 其它类型的contentType, 未做处理, 直接输出
content.append(part.getContent().toString());
}
}
public static void saveAttachment(Part part, String destDir) throws Exception {
if (part == null) {
throw new MessagingException("part is empty");
}
// 复杂的邮件包含多个邮件体
if (part.isMimeType("multipart/*")) {
Multipart mp = (Multipart) part.getContent();
// 遍历每一个邮件体
for (int i = 0; i mp.getCount(); i++) {
BodyPart bodyPart = mp.getBodyPart(i);
// bodyPart也可能有多个邮件体组成
String disposition = bodyPart.getDisposition();
if (disposition == null (Part.ATTACHMENT.equalsIgnoreCase(disposition)
|| Part.INLINE.equalsIgnoreCase(disposition))) {
InputStream in = bodyPart.getInputStream();
saveFile(in, destDir, decodeText(bodyPart.getFileName()));
} else if (bodyPart.isMimeType("multipart/*")) {
saveAttachment(bodyPart, destDir);
} else {
String contentType = bodyPart.getContentType();
if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) {
saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName()));
}
}
}
} else if (part.isMimeType("message/rfc822")) {
saveAttachment((Part) part.getContent(), destDir);
}
}
public static void saveFile(InputStream in, String destDir, String fileName) throws Exception {
FileOutputStream out = new FileOutputStream(new File(destDir + fileName));
byte[] buffer = new byte[1024];
int length = 0;
while ((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length);
}
out.close();
in.close();
}
public static String decodeText(String encodedText) throws Exception {
if (encodedText == null || "".equals(encodedText.trim())) {
return "";
} else {
return MimeUtility.decodeText(encodedText);
}
}
java 代码解析
设u和v是类A的两个对象——u和v是类A的两个实例?
u==v
的意思是判断u和v是否是同一个实例。
如果返回true,表示u和v是A的同一个实例。
如果返回false,表示u和v是A的两个不同实例。
电商网站 java 如何校验收货地址
这个我猜的,
一般省 - 市 - 县/区 这些三级联动
然后就是具体的地址。
这些地址有可能是它们买的,也有可能是自己积累过来的。
例如用户填写了一个地址,只要这个订单成功送达,这个地址就进入有效库。京东用户那么多,数据积累量肯定没问题。
java抓包解析后ip地址输出到一个数组元素a[12]中,如何将相同ip地址数目统计并输出?求源码
private String s = "";//这个就是要求的a[12]
private ListString getTestAddress(){//这个测试方法改成你解析IP的方法
ListString address = new ArrayListString();
address.add("192.168.1.60");
address.add("192.168.1.61");
address.add("192.168.2.60");
address.add("192.168.1.60");
address.add("192.168.1.63");
address.add("192.168.1.64");
address.add("192.168.1.65");
address.add("192.168.2.60");
address.add("192.168.1.60");
return address;
}
private MapString, Integer getAddressNumber(){//把每一个ip跟其数量放入映射中,如果数量为0,表示无重复IP
MapString, Integer map = new HashMapString, Integer();
ListString address = getTestAddress();
for(int i=0; iaddress.size(); i++){
String ip1 = address.get(i);
s = s + ip1 + ",";//将IP组合成字符串,然后赋值给a[12]
int number = 0;
for(int j=address.size()-1; j i; j--){
String ip2 = address.get(j);
if(ip1.equals(ip2))
number += 1;
}
map.put(ip1, number);
}
return map;
}
文章题目:java收货地址解析代码 收货地址代码怎么写
新闻来源:http://azwzsj.com/article/docdpji.html