android的webseetings.java中有设置ua的代码,通过一系列字符串拼接而成。
private synchronized String getCurrentUserAgent() {
Locale locale;
synchronized(sLockForLocaleSettings) {
locale = sLocale;
}
StringBuffer buffer = new StringBuffer();
// Add version
final String version = Build.VERSION.RELEASE;
if (version.length() > 0) {
if (Character.isDigit(version.charAt(0))) {
// Release is a version, eg "3.1"
buffer.append(version);
} else {
// Release is a codename, eg "Honeycomb"
// In this case, use the previous release's version
buffer.append(PREVIOUS_VERSION);
}
} else {
// default to "1.0"
buffer.append("1.0");
}
buffer.append("; ");
final String language = locale.getLanguage();
if (language != null) {
buffer.append(convertObsoleteLanguageCodeToNew(language));
final String country = locale.getCountry();
if (country != null) {
buffer.append("-");
buffer.append(country.toLowerCase());
}
} else {
// default to "en"
buffer.append("en");
}
buffer.append(";");
// add the model for the release build
if ("REL".equals(Build.VERSION.CODENAME)) {
final String model = Build.MODEL;
final String brand = Build.BRAND;
if (brand.length() > 0) {
buffer.append(" ");
buffer.append(brand);
}
if (model.length() > 0) {
buffer.append(" ");
buffer.append(model);
}
}
final String id = Build.ID;
if (id.length() > 0) {
buffer.append(" Build/");
buffer.append(id);
}
String mobile = mContext.getResources().getText(
com.android.internal.R.string.web_user_agent_target_content).toString();
final String base = mContext.getResources().getText(
com.android.internal.R.string.web_user_agent).toString();
return String.format(base, buffer, mobile);
}
浏览器地址栏输入:javascript:window.navigator.userAgent
通过网站查询:
http://www.enhanceie.com/ua.aspx
http://www.useragentstring.com/
http://whatsmyuseragent.com/
Google搜索“ what is my user agent”
修改User Agent:
Chrome在快捷方式的目标后加上–user-agent="User Agent String"选项,形如chrome.exe -user-agent="User Agent String"。
Firefox使用User Agent Switcher扩展来切换User-Agent
Chrome使用User-Agent Switcher for Chrome扩展来切换User-Agent
Safari中:偏好设置(Ctrl+,)->高级->在菜单栏显示“开发”菜单,然后“开发”菜单->用户代理。
傲游:选项->高级->自定义UserAgent字符串。
就可以直接在电脑上查看为移动设备如手机、平板开发的网页
针对我等个人站长,在登录和使用后台时,可以先判断user-agent中是否有指定字符串(或计算指定部分的md5值等),这样除非抓包或者修改源码,否则就算知道密码,也没办法使用后台.