Android中Parcel的分析以及使用

Android中Parcel的分析以及使用

简单点来说:Parcel就是一个存放读取数据的容器, Android系统中的binder进程间通信(IPC)就使用了Parcel类来进行客户端与服务端数据的交互,而且AIDL的数据也是通过Parcel来交互的。在Java空间和C++都实现了Parcel,由于它在C/C++中,直接使用了内存来读取数据,因此,它更有效率。

分析Binder机制中的客户端与服务器端进行实际操作ontransact()函数 :

  1. //参数说明:   
  2. // code :是请求的ID号    
  3. // data :客户端请求发送的参数   
  4. // reply:服务器端返回的结果   
  5. // flags:一些额外的标识,如FLAG_ONEWAY等,通常为0.   
  6. virtual status_t    onTransact( uint32_t code,
  7.                                 const Parcel& data,  
  8.                                 Parcel* reply,
  9.                                 uint32_t flags = 0);  

从中我们可以看到Parcel的重要性以及窥探它的使用情况,接下来,我主要分析它的存储机制。

    常用方法介绍:

            obtain()                          获得一个新的parcel ,相当于new一个对象

            dataSize()                      得到当前parcel对象的实际存储空间

            dataCapacity()               得到当前parcel对象的已分配的存储空间, >=dataSize()值  (以空间换时间)

            dataPostion()                 获得当前parcel对象的偏移量(类似于文件流指针的偏移量)

            setDataPosition()           设置偏移量

            recyle()                           清空、回收parcel对象的内存

            writeInt(int)                     写入一个整数

            writeFloat(float)              写入一个浮点数

            writeDouble(double)       写入一个双精度数

            writeString(string)           写入一个字符串

         当然,还有更多的writeXXX()方法,与之对应的就是readXXX(),具体方法请参阅SDK。

          其中几个值得注意的方法为:

             writeException()        在Parcel队头写入一个异常

             writeException()        Parcel队头写入“无异常“

             readException()        在Parcel队头读取,若读取值为异常,则抛出该异常;否则,程序正常运行。

一、Parcel的分析

       相信看了前面的值,对Parcel的使用该有了初步印象。那么,Parcel的内部存储机制是怎么样的?偏移量又是

  什么情况?让我们回忆一下基本数据类型的取值范围:

                   boolean     1bit          1字节

                   char          16bit         2字节

                   int             32bit        4字节

                   long          64bit        8字节

                   float          32bit        4字节

                  double       64bit         8字节

        如果大家对C语言熟悉的话,C语言中结构体的内存对齐和Parcel采用的内存存放机制一样,即读取*小字节

为32bit,也即4个字节。高于4个字节的,以实际数据类型进行存放,但得为4byte的倍数。基本公式如下:

             实际存放字节:

                       判别一:  32bit      (<=32bit)             例如:boolean,char,int

                       判别二:  实际占用字节(>32bit)     例如:long,float,String,数组等

        当我们使用readXXX()方法时,读取方法也如上述:

              实际读取字节:

                        判别一:  32bit      (<=32bit)            例如:boolean,char,int

                        判别二:  实际字节大小(>32bit)     例如:long,float,String,数值等

 

由上可以知道,当我们写入/读取一个数据时,偏移量至少为4byte(32bit),于是,偏移量的公式如下:

f(x)= 4x  (x=0,1,…n)

 

事实上,我们可以显示的通过setDataPostion(int postion) 来直接操作我们欲读取数据时的偏移量。毫无疑问,

你可以设置任何偏移量,但所读取的值是类型可能有误。因此显示设置偏移量读取值的时候,需要小心。

 

另外一个注意点就是我们在writeXXX()和readXXX()时,导致的偏移量是共用的,例如,我们在writeInt(23)后,

此时的datapostion=4,如果我们想读取5,简单的通过readInt()是不行的,只能得到0。这时我们只能通过

setDataPosition(0)设置为起始偏移量,从起始位置读取四个字节,即23。因此,在读取某个值时,可能需要使用

setDataPostion(int postion)使偏移量装换到我们的值处。

 

巧用setDataPosition()方法,当我们的parcel对象中只存在某一类型时,我们就可以通过这个方法来快速的读取

所有值。具体方法如下:

 

  1. /**
  2.      * 前提条件,Parcel存在多个类型相同的对象,本例子以10个float对象说明:
  3.      */
  4.     public void readSameType() {
  5.         Parcel parcel =Parcel.obtain() ;  
  6.         for (int i = 0; i < 10; i++) {  
  7.             parcel.writeDouble(i);
  8.             Log.i(TAG, “write double —-> ” + getParcelInfo());  
  9.         }
  10.         //方法一 ,显示设置偏移量
  11.         int i = 0;  
  12.         int datasize = parcel.dataSize();  
  13.         while (i < datasize) {  
  14.             parcel.setDataPosition(i);
  15.             double fvalue = parcel.readDouble();  
  16.             Log.i(TAG, ” read double is=” + fvalue + “, —>” + getParcelInfo());  
  17.             i += 8; // double占用字节为 8byte
  18.         }
  19. //      方法二,由于对象的类型一致,我们可以直接利用readXXX()读取值会产生偏移量
  20. //      parcel.setDataPosition(0)  ;  //
  21. //      while(parcel.dataPosition()<parcel.dataSize()){
  22. //          double fvalue = parcel.readDouble();  
  23. //          Log.i(TAG, ” read double is=” + fvalue + “, —>” + getParcelInfo());  
  24. //      }
  25.     }

 

由于可能存在读取值的偏差,一个默认的取值规范为:

1、  读取复杂对象时: 对象匹配时,返回当前偏移位置的该对象;

对象不匹配时,返回null对象 ;

2、  读取简单对象时: 对象匹配时,返回当前偏移位置的该对象 ;

对象不匹配时,返回0;

下面,给出一张浅显的Parcel的存放空间图,希望大家在理解的同时,更能体味其中滋味。有点简单,求谅解。

%title插图%num

相信通过前面的介绍,你一定很了解了了Parcel的存储机制,下面给定一应用程序来实践。

     1、布局文件如下:

  1. <?xml version=“1.0” encoding=”utf-8″?>  
  2. <LinearLayout xmlns:Android=“http://schemas.android.com/apk/res/android”  
  3.     android:orientation=“vertical” android:layout_width=”fill_parent”  
  4.     android:layout_height=“fill_parent”>  
  5.     <TextView android:layout_width=“fill_parent”  
  6.         android:layout_height=“wrap_content” android:text=”@string/hello” />  
  7.     <LinearLayout android:orientation=“horizontal”  
  8.         android:layout_width=“fill_parent” android:layout_height=”wrap_content”>  
  9.         <Button android:id=“@+id/btWriteByte” android:layout_width=”wrap_content”  
  10.             android:layout_height=“wrap_content” android:text=”写入一个byte值”></Button>  
  11.         <Button android:id=“@+id/btWriteInt” android:layout_width=”wrap_content”  
  12.             android:layout_height=“wrap_content” android:text=”写入一个int值”></Button>  
  13.     </LinearLayout>
  14.     <LinearLayout android:orientation=“horizontal”  
  15.         android:layout_width=“fill_parent” android:layout_height=”wrap_content”>  
  16.         <Button android:id=“@+id/btWriteDouble” android:layout_width=”wrap_content”  
  17.             android:layout_height=“wrap_content” android:text=”写入一个double值”></Button>  
  18.         <Button android:id=“@+id/btWriteString” android:layout_width=”wrap_content”  
  19.             android:layout_height=“wrap_content” android:text=”写入一个String值”></Button>  
  20.     </LinearLayout>
  21.     <View android:layout_width=“fill_parent” android:layout_height=”2dip”  
  22.         android:background=“#FF1493”></View>  
  23.     <LinearLayout android:orientation=“horizontal”  
  24.         android:layout_marginTop=“5dip” android:layout_width=”fill_parent”  
  25.         android:layout_height=“wrap_content”>  
  26.         <Button android:id=“@+id/btReadByte” android:layout_width=”wrap_content”  
  27.             android:layout_height=“wrap_content” android:text=”读取一个byte值”></Button>  
  28.         <Button android:id=“@+id/btReadInt” android:layout_width=”wrap_content”  
  29.             android:layout_height=“wrap_content” android:text=”读取一个int值”></Button>  
  30.     </LinearLayout>
  31.     <LinearLayout android:orientation=“horizontal”  
  32.         android:layout_width=“fill_parent” android:layout_height=”wrap_content”>  
  33.         <Button android:id=“@+id/btReadDouble” android:layout_width=”wrap_content”  
  34.             android:layout_height=“wrap_content” android:text=”读取一个double值”></Button>  
  35.         <Button android:id=“@+id/btReadString” android:layout_width=”wrap_content”  
  36.             android:layout_height=“wrap_content” android:text=”读取一个String值”></Button>  
  37.     </LinearLayout>
  38.     <View android:layout_width=“fill_parent” android:layout_height=”2dip”  
  39.         android:background=“#FF1493”></View>  
  40.     <Button android:id=“@+id/btSameType” android:layout_width=”wrap_content”  
  41.         android:layout_height=“wrap_content” android:text=”利用setDataPosition读取多个值”></Button>  
  42. </LinearLayout>   

 2、配置文件如下:

[html]

  1. <?xml version=“1.0” encoding=”utf-8″?>  
  2. <manifest xmlns:android=“http://schemas.android.com/apk/res/android”  
  3.       package=“com.qinjuning.parcel”  
  4.       android:versionCode=“1”  
  5.       android:versionName=“1.0”>  
  6.     <application android:icon=“@drawable/icon” android:label=”@string/app_name”>  
  7.         <activity android:name=“.MainActivity”  android:label=”@string/app_name”>  
  8.             <intent-filter>
  9.                 <action android:name=“android.intent.action.MAIN” />  
  10.                 <category android:name=“android.intent.category.LAUNCHER” />  
  11.             </intent-filter>
  12.         </activity>
  13.     </application>
  14. </manifest>

     3、程序主文件如下:

  1. public class MainActivity extends Activity implements OnClickListener {
  2.     private static String TAG = “PARCELTEST”;  
  3.     // Button ID
  4.     private static int[] btIds = new int[] { R.id.btWriteByte, R.id.btWriteInt,  
  5.             R.id.btReadDouble, R.id.btWriteString, R.id.btReadByte,
  6.             R.id.btReadInt, R.id.btReadDouble, R.id.btReadString,
  7.             R.id.btSameType };
  8.     // 每种类型的当前值
  9.     private byte cur_byte = 1; // 每次总写入 false  
  10.     private int cur_int = 10; // 写入值 cur_int ++ ;  
  11.     private double cur_float = 100.0d; // 写入值 cur_float++ ;  
  12.     private String cur_str = “QinJun –>” + cur_int; // 写入值 “QinJun —>“+cur_int  
  13.     private Parcel parcel = null;  
  14.     @Override
  15.     public void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.main);
  18.         for (int i = 0; i < btIds.length; i++) {  
  19.             Button bt = (Button) findViewById(btIds[i]);  
  20.             bt.setOnClickListener(this);
  21.         }
  22.         parcel = Parcel.obtain(); // 获得一个Parcel对象 ,相当于new一个,初始大小为0  
  23.         Log.i(TAG, “The original parcel info” + getParcelInfo());
  24.     }
  25.     @Override
  26.     public void onClick(View view) {
  27.         // TODO Auto-generated method stub
  28.         int viewviewId = view.getId();  
  29.         switch (viewId) {
  30.         case R.id.btWriteByte:
  31.             parcel.setDataPosition(0);
  32.             parcel.writeByte(cur_byte);
  33.             Log.i(TAG, ” after write byte, —>” + getParcelInfo());  
  34.             break;
  35.         case R.id.btWriteInt:
  36.             parcel.writeInt(cur_int);
  37.             Log.i(TAG, ” after write int, —>” + getParcelInfo());  
  38.             break;
  39.         case R.id.btWriteDouble:
  40.             parcel.writeDouble(cur_float);
  41.             Log.i(TAG, ” after write float, —>” + getParcelInfo());  
  42.             break;
  43.         case R.id.btWriteString:
  44.             parcel.writeString(cur_str);
  45.             Log.i(TAG, ” after write String, —>” + getParcelInfo());  
  46.             break;
  47.         case R.id.btReadByte:
  48.             byte b = parcel.readByte();  
  49.             Log.i(TAG, ” read byte is=” + b + “, —>” + getParcelInfo()  
  50.                     + “String”);
  51.             break;
  52.         case R.id.btReadInt:
  53.             int i = parcel.readInt();  
  54.             Log.i(TAG, ” read int is=” + i + “, —>” + getParcelInfo());  
  55.             break;
  56.         case R.id.btReadDouble:
  57.             float f = parcel.readFloat();  
  58.             readSameType();
  59.             Log.i(TAG, ” read float is=” + f + “, —>” + getParcelInfo());  
  60.             break;
  61.         case R.id.btReadString:
  62.             parcel.setDataPosition(0);
  63.             String str = parcel.readString();  
  64.             Log.i(TAG, ” read float is=” + str + “, —>” + getParcelInfo());  
  65.             break;
  66.         case R.id.btSameType:
  67.             readSameType();
  68.             break;
  69.         default:
  70.             break;
  71.         }
  72.     }
  73.     private String getParcelInfo() {// 得到parcel的信息
  74.         return “dataSize = ” + parcel.dataSize() + “, dataCapacity=”  
  75.                 + parcel.dataCapacity() + “, dataPositon = ”  
  76.                 + parcel.dataPosition();
  77.     }
  78.     /**
  79.      * 前提条件,Parcel存在多个类型相同的对象,本例子以10个float对象说明:
  80.      */
  81.     public void readSameType() {
  82.         for (int i = 0; i < 10; i++) {  
  83.             parcel.writeDouble(i);
  84.             Log.i(TAG, “write double —-> ” + getParcelInfo());  
  85.         }
  86.         //方法一 ,显示设置偏移量
  87.         int i = 0;  
  88.         int datasize = parcel.dataSize();  
  89.         while (i < datasize) {  
  90.             parcel.setDataPosition(i);
  91.             double fvalue = parcel.readDouble();  
  92.             Log.i(TAG, ” read double is=” + fvalue + “, —>” + getParcelInfo());  
  93.             i += 8; // double占用字节为 8byte
  94.         }
  95. //      方法二,由于对象的类型一致,我们可以直接利用readXXX()读取值会产生偏移量
  96. //      parcel.setDataPosition(0)  ;  //
  97. //      while(parcel.dataPosition()<parcel.dataSize()){
  98. //          double fvalue = parcel.readDouble();  
  99. //          Log.i(TAG, ” read double is=” + fvalue + “, —>” + getParcelInfo());  
  100. //      }
  101.     }
  102. }

由于取值时,可能存在类型的转换,因此点击按钮时,可能不会产生预期结果。因此,得保证偏移量对应数值的正确性。

Android ProgressBar手动控制开始和停止

Android ProgressBar手动控制开始和停止

这两天有个需求,点击按钮从SD卡解压压缩包,并读取压缩包内txt文档内容,然后在街面上显示出来。毕竟IO操作很耗时,如果文件较大会花费不少时间。所以,在处理数据的时候能给个进度就好了。我们通常的做法就是,点击按钮后弹出一个加载框或者加载进度条,等数据处理结束后,再让对话框消失。

但是现在的需求是,用一个布局,左侧显示刷新列表,右侧显示ProgressBar。那么问题来了,ProgressBar显示的很大,而且打开后就一直在转动,无法控制。那么就来解决这两个问题吧~

%title插图%num

*个问题:控制ProgressBar的大小和样式

首先,创建一个style样式,设置宽高和图片,具体如下:

<style name="ProgressCircle">
    <item name="android:indeterminateDrawable">@drawable/ic_refresh_grey_600_24dp</item>
    <item name="android:minWidth">25dp</item>
    <item name="android:minHeight">25dp</item>
    <item name="android:maxWidth">60dp</item>
    <item name="android:maxHeight">60dp</item>
</style>

然后,写一个xml文件progressbar_circle.xml,设置ProgressBar的转动效果。

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/ic_refresh_grey_600_24dp"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="360">
</rotate>

到这里,大小固定,转动效果也有了。

第二个问题:手动控制转动的开始和停止

开始的时候,设置setIndeterminateDrawable和setProgressDrawable为定义的xml文件,即可开始转动。

结束的时候,设置setIndeterminateDrawable和setProgressDrawable为固定的图片,即可停止转动。

/**
 * 开始刷新动画
 */
public void startRefresh() {
   progressbar_refresh.setIndeterminateDrawable(getResources().getDrawable(
         R.drawable.progressbar_circle));
   progressbar_refresh.setProgressDrawable(getResources().getDrawable(
         R.drawable.progressbar_circle));
}

/**
 * 停止刷新动画
 */
public void stopRefresh() {
   progressbar_refresh.setIndeterminateDrawable(getResources().getDrawable(
         R.drawable.ic_refresh_grey_600_24dp));
   progressbar_refresh.setProgressDrawable(getResources().getDrawable(
         R.drawable.ic_refresh_grey_600_24dp));
}

以上。

Android自定义进度条颜色

Android自定义进度条颜色

 

这个没法了只能看源码了,还好下载了源码, sources\base\core\res\res\ 下应有尽有,修改进度条颜色只能找progress ,因为是改变样式,首先找styles.xml

1
2
3
4
5
6
7
8
9
10
<style name="Widget.ProgressBar">
    <item name="android:indeterminateOnly">true</item>
    <itemname="android:indeterminateDrawable">@android:drawable/progress_medium_white</item>
    <item name="android:indeterminateBehavior">repeat</item>
    <item name="android:indeterminateDuration">3500</item>
    <item name="android:minWidth">48dip</item>
    <item name="android:maxWidth">48dip</item>
    <item name="android:minHeight">48dip</item>
    <item name="android:maxHeight">48dip</item>
</style>

进度条颜色,所以找到:

?
1
2
3
4
5
6
7
<style name="Widget.ProgressBar.Horizontal">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
    <itemname="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
    <item name="android:minHeight">20dip</item>
    <item name="android:maxHeight">20dip</item>
</style>

Android:progressDrawable”>  所以我们可以找到”drawable下的 progress_horizontal 文件,改变他就可以改变进度条颜色。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2008 The Android Open Source Project
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
          http://www.apache.org/licenses/LICENSE-2.0
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="5dip" />
            <gradient
                android:angle="270"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:startColor="#ff9d9e9d" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:angle="270"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:startColor="#80ffd300" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:angle="270"
                    android:centerColor="#ffffb600"
                    android:centerY="0.75"
                    android:endColor="#ffffcb00"
                    android:startColor="#ffffd300" />
            </shape>
        </clip>
    </item>
</layer-list>

 

?
1
2
3
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:endColor="#ff747674"

 

在我们的项目下新建一个 style.xml 文件

 

?
1
2
3
4
5
6
7
<style name="ProgressBar_Mini" parent="@android:style/Widget.ProgressBar.Horizontal">
    <item name="android:maxHeight">50dip</item>
    <item name="android:minHeight">8dip</item>
    <item name="android:indeterminateOnly">false</item>
    <itemname="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
    <item name="android:progressDrawable">@drawable/progressbar_mini</item>
</style>

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="5dip" />
            <gradient
                android:angle="270"
                android:centerY="0.75"
                android:endColor="#F5F5F5"
                android:startColor="#BEBEBE" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="0dip" />
                <gradient
                    android:angle="270"
                    android:centerY="0.75"
                    android:endColor="#165CBC"
                    android:startColor="#85B0E9" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:angle="270"
                    android:centerY="0.75"
                    android:endColor="#165CBC"
                    android:startColor="#85B0E9" />
            </shape>
        </clip>
    </item>
</layer-list>

?

1
2
3
4
5
6
<ProgressBar
    android:id="@+id/progress"
    style="@style/ProgressBar_Mini"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:progress="50" />

 

VPS 自建邮件服务器方案求推荐

手上有7-8个域名,所以要个比较方便维护的面板。
因为是给学校小伙伴用的,所以还需要能够自助注册的功能。
之前试过CENTOS装zpenal
还有win2003装winwebmail,
winwebmail的SSL证书不能支持多域名,多域名证书又太贵
效果都不理想啊
还有一个z什么什么ma的不会装。愁死了。
域名 winwebmail 证书5 条回复 • 2014-12-03 17:47:38 +08:00
kkxxxxxxx 1
kkxxxxxxx 2014-11-03 22:05:15 +08:00
第三方邮件服务不是更稳定么
yylzcom 2
yylzcom 2014-11-03 22:25:13 +08:00
zimbra?自建邮件服务器*怕被大域名商列入黑名单,一发邮件就进垃圾箱,蛋疼无比
我觉得还是第三方好了,不过话说回来,还有什么比较好的第三方吗?
zq9610 3
zq9610 2014-11-04 14:15:02 +08:00
@yylzcom
@kkxxxxxxx 同问。
leif 4
leif 2014-11-04 14:28:43 +08:00
iredmail才是王道
popu111 5
popu111 2014-12-03 17:47:38 +08:00
@leif Apache配置ssl证书有点麻烦。。。

外网 Windows 服务器被黑

今早来公司,无意中发现远程桌面无法复制粘贴,仔细一看进程,多了一个傲游浏览器进程,发现不对.逐步寻找,发现所有关于安全的程序都被杀了,无法再次启动.随即通告网管,结果得到答案是从新安装系统.当时直接崩溃,马上检查数据库服务器发现内网服务器没问题.继而下载360杀毒,直接给查杀出来了,但悲剧的是重启服务器病毒依然存在.唉…

现在只能唉声叹气,求靠谱杀软,应用服务器重装系统还是挺悲剧的.
服务器 进程 器重36 条回复 • 2015-09-19 15:50:51 +08:00
seki 1
seki 2014-09-15 20:47:28 +08:00
用 360 查服务器病毒,醉了

全盘格式化,加高防火墙,堵掉所有端口,打好各类补丁才是正道。万一有一些没有进入病毒库的病毒你们还会中招的
alex321 2
alex321 2014-09-15 20:56:32 +08:00
给机会你体验手工杀毒的快感啊。
zro 3
zro 2014-09-15 21:00:39 +08:00
神马网管,居然用360,Orz
xdeng 4
xdeng 2014-09-15 21:05:09 +08:00
@zro 那是之后

之前为什么不用360 ?
can 5
can 2014-09-15 21:12:41 +08:00
人都死了,医术再高明的的医生也无能为力啊
omi4399 6
omi4399 2014-09-15 21:15:10 +08:00
重装吧,什么杀软也白搭了
linchanx 7
linchanx 2014-09-15 21:16:45 +08:00
连接外网的服务器前面一定要挡一台防火墙,切记。
7654 8
7654 2014-09-15 21:18:45 +08:00
格盘,重装系统是*稳妥,谁知道有没有潜伏的病毒某天悄悄发作
aa45942 9
aa45942 2014-09-15 21:21:57 +08:00
1.重启进不带网络的安全模式
2.找启动项,可疑的k掉(开始,运行,MSConfig)
3.从U盘拷贝一个杀软到服务器
4.运行杀软前看看注册表里可执行程序后缀是不是被绑了多余的东西,是的话先找可疑进程k掉,改注册表,重启
5.装杀软,扫全盘
6.重启
7.毒还在的话,要么你的杀软不给力没清理干净,要么服务器有漏洞

============
其实更方便的是拿被检测到的病毒的文件名做关键字去百度或者谷歌一下,99%有解决的办法
thinkxen 10
thinkxen 2014-09-15 21:38:28 +08:00 via Android
话说安全狗还是很不错的,指定ip登录。
ky1e 11
ky1e 2014-09-15 21:48:55 +08:00
win2008r2么?什么系统?
zro 12
zro 2014-09-15 21:49:16 +08:00
话说,把重要数据备份出来再格盘重装系统吧,这样盲杀病毒很耗时,而且也不一定能弄干净,而且装完系统*好是把补丁更新给打上
touzi 13
touzi 2014-09-15 22:13:28 +08:00
@zro 哥你告诉我用什么,现在还在修复…
Admstor 14
Admstor 2014-09-15 22:14:29 +08:00
看到用360也是醉了…
touzi 15
touzi 2014-09-15 22:15:26 +08:00
@zro 话说打补丁,我是听杀软的还是听微软的(微软自带update一直开着.)
touzi 16
touzi 2014-09-15 22:16:12 +08:00
@Admstor 亡羊补牢,什么杀软*合适
zro 17
zro 2014-09-15 22:17:06 +08:00
@touzi ESET,AVG,或者微软自己的MSE,希望能帮到你
harryert 18
harryert 2014-09-15 22:19:56 +08:00
弄个pfsense放到windows服务器前面,然后端口映射吧。

现有服务器,PE启动杀毒把。。。
zro 19
zro 2014-09-15 22:22:13 +08:00
@touzi 微软自带的就行了,国产的补丁提示不怎么靠谱,当年360还自带一款伪IE补丁
ScotGu 20
ScotGu 2014-09-15 22:52:53 +08:00
服务器用 360 这个创意太赞了。。
touzi 21
touzi 2014-09-15 23:06:51 +08:00
@ScotGu 那你装的是什么?
Bakemono 22
Bakemono 2014-09-15 23:13:04 +08:00
不要相信 ls 的 360 黑们。
服务器安装 360 很多提权的 exp 还有很多马都不能用了,完全是渗透的一大阻力…
ipconfiger 23
ipconfiger 2014-09-15 23:21:57 +08:00
一般来说别在服务器上跑非服务的应用程序,不必要的端口一律禁用掉,把ping也关掉,换个高强度的登录密码,应该可以挡掉很大部分的入侵。前段时间入了个linode的vps跑shadowsocket,当时偷了个懒,设置好shadowsocket就没继续做安全设置就放那里了,结果当月就被人当了肉鸡刷了30美刀的流量。回头立马配置了一下iptables,关端口,禁用密码登录,立马就清净了。windows服务器一般来说做完关端口,关不必要的服务,别再服务器上挂QQ,开浏览器看网页,基本上没啥可以中毒的机会吧
ScotGu 24
ScotGu 2014-09-15 23:22:04 +08:00
@touzi 装什么也不装360 。。。 我承认我就是360黑。
360的负面新闻和所作所为这个圈子里的人就不用多说了吧。

服务器前放个防火墙很容易吧。。
HackerOO7 25
HackerOO7 2014-09-16 00:19:37 +08:00 via Android
应该要有人负责安全这块吧啊,好吧,360……
hjc4869 26
hjc4869 2014-09-16 09:59:28 +08:00 via iPhone
这种水平还是不要用windows server了,老老实实linux在前面挡着吧,别把windows暴露在外面
Admstor 27
Admstor 2014-09-16 10:04:48 +08:00
@touzi
服务器用杀毒软件本身就是一个伪命题.

服务器理论上为什么会需要杀毒软件?除非你要帮客户杀毒,否则任何来自外部的文件,都不应当具有运行的权限,那么是不是病毒又有什么关系了?
进一步说,如果外部文件可以运行并感染系统,当然是要首先排除掉让外部文件运行的可能

竟然以为用个杀软就可以让服务器安全,这种思维才是*让人醉了

我虽然是360黑,不过你非要用360,麻烦也不要用什么360安全卫士这种东西好吗,人家360自己都没说这个适合服务器用
http://webscan.360.cn/ 来自360的网页安全扫描工具,可以初步的帮你判断你的网站是否存在漏洞
http://jk.cloud.360.cn 来自360的监控服务器,可以不必自己搭建cacti或者zaibbx之类

另外小白就还是用安全狗吧
chinafeng 28
chinafeng 2014-09-16 11:45:24 +08:00
用360,也是醉了…

分析下日志,就还知道该清理哪里了
aa45942 29
aa45942 2014-09-16 13:15:36 +08:00
@Admstor 你得考虑到服务器被黑的可能,没杀软,被黑了,也就有了被执行外部程序的可能。其实相对杀软,一个好的防火墙才是重中之重,好的防火墙能挡掉*大部分骚扰
xseven007 30
xseven007 2014-09-16 21:30:16 +08:00
服务器遭到入侵,查日志肯定是必须的啊..接外网必须要有硬件墙啊,本机可以再配个SEP
zy65334 31
zy65334 2014-09-17 15:57:30 +08:00
没有百分之百的安全,只能通过手段降低安全风险。昨天才看到有人在出windows 提权 0day 包含XP 2003 7 2008 x32 x64通杀。
zy65334 32
zy65334 2014-09-17 15:58:19 +08:00
一般被入侵提权到管理员权限了的话,我们给客户的建议就是重装系统。
touzi 33
touzi 2014-09-17 16:51:35 +08:00
@zy65334 已经在重装系统了,网管不管,只能靠自己了.
mackyzhan 34
mackyzhan 2014-11-28 22:36:45 +08:00 via Android
用360?就这水平还管理什么服务器呀
touzi 35
touzi 2014-11-28 23:11:11 +08:00
@mackyzhan 那怎么办,不格机子的办法。
Pepsigold 36
Pepsigold 2015-09-19 15:50:51 +08:00 via Android
我的服务器也没有杀软,也不懂安全,求个大牛指导下。帮忙做下隐患分析呗!

求推荐 JP 的 VPS

其实个人有点看好樱花的VPS,但是由于找不到代购,所以现在想各位V友介绍几个JP的VPS,或者有没有V友做樱花代购的。
VPS 樱花 代购8 条回复 • 2015-03-31 19:20:21 +08:00
ryd994 1
ryd994 2014-12-04 23:42:32 +08:00
linode,ablenet,vultr,都可以
我用过linode和ablenet,都还行
网络条件不评价,因为每个人都不同
买的话,linode和vultr都不是日本公司,而ablenet是默许外国人买的,有英文客服
所以只要有张能外币支付的信用卡都能买
rainy3636 2
rainy3636 2014-12-05 18:10:38 +08:00
http://www.rbvps.com/
Kilerd 3
Kilerd 2014-12-05 21:53:36 +08:00
@rainy3636 各种黑,是我见过樱花代购里面算贵的
rainy3636 4
rainy3636 2014-12-05 21:59:53 +08:00
@Kilerd 樱花*近才降价,你可以跟他谈谈,不知会不会改
xiaozhizhu1997 5
xiaozhizhu1997 2014-12-06 11:45:44 +08:00 via Android
樱花电信基本没法用。。。
Linode适合电信…vultr也还行
Lavender 6
Lavender 2014-12-09 12:18:27 +08:00
目前有款首月免费 续费七折的VPS
要试试么
美国的
有兴趣可以扣我 QQ 2510087799
molinxx 7
molinxx 2014-12-09 14:41:43 +08:00
ConoHa.JP
justff 8
justff 2015-03-31 19:20:21 +08:00
kagoya.jp

三台 vps 如何加快访问速度

用的百度云加速代备案的,怕掉备案,只能用云加速隐藏ip,但是手贱买了三台vps

1.亚马逊的速度很好,但是流量不够
2.搬瓦工的感觉速度不错,但是性能太弱
3.另一个不知名的性能很好,但是速度不是很快

网速:
亚马逊》搬瓦工》无名

性能:
无名》亚马逊》搬瓦工

流量只有亚马逊的不够,其他的都用不完,能支支招吗,亚马逊的是xen,另外两个都是ovz。一点都不想浪费啊,有什么办法没有啊,谢谢大神

瓦工 备案 VPS10 条回复
wesley 1
wesley 2014-12-29 16:44:41 +08:00 ❤️ 1
应用服务放aws
静态文件放搬瓦工
无名做备用,如果跟aws之间速度不错可以放数据库
1063141514 2
1063141514 2014-12-29 18:12:20 +08:00 ❤️ 1
你什么网? 我这里搬瓦工0K/S
zzutmebwd 3
zzutmebwd 2014-12-29 18:34:06 +08:00 via Android
还有比搬砖工还慢的…
那就买个大号搬砖工不就妥了么
Starduster 4
Starduster 2014-12-29 18:44:50 +08:00
我倒是很好奇你怎么备案的
z742364692 5
z742364692 2014-12-29 19:28:26 +08:00
@Starduster 用百度云加速代理备案
z742364692 6
z742364692 2014-12-29 19:29:08 +08:00
@wesley 那我看到有人说做什么跳板是怎么回事啊
z742364692 7
z742364692 2014-12-29 19:29:27 +08:00
@1063141514 四川移动的线路
z742364692 8
z742364692 2014-12-29 19:30:06 +08:00
@zzutmebwd 买了。。。。。512的,感觉还是性能差,只能跑一千多。
Starduster 9
Starduster 2014-12-29 20:16:12 +08:00
@z742364692 = = 可是没有国内接入商也能代备案?百度神了。。。
z742364692 10
z742364692 2014-12-29 20:27:11 +08:00
@Starduster 现在都这样,360也是

大家的服务器有没有取客户端 IP 经常出错的?

本人的网站,要取客户端IP,但经常取到的IP不对,比如取一个福建客户100次ip,福建的IP大约80个,其他地区错误IP有20个左右,频率很高,至今未能查明到底出错在服务器端还是客户端

出错 服务器 查明6 条回复 • 2014-12-30 03:31:44 +08:00
yfdyh000 1
yfdyh000 2014-12-29 23:53:42 +08:00
客户ISP的问题吧,大型内网,IP经常变、到处飘。
w88975 2
w88975 2014-12-29 23:56:17 +08:00
@yfdyh000 有没有办法保证取得的IP为真正的IP呢?或者只需要IP所在地正确就行了
yfdyh000 3
yfdyh000 2014-12-30 00:12:47 +08:00
@w88975 这些ISP的客户本就没有全球唯一的IPv4地址,外网出口IP可能是随机的,并可能跨区域。不清楚其他网站是怎么处理的。
Septembers 4
Septembers 2014-12-30 00:25:33 +08:00
http://tool.17mon.cn/ 这个IP库的精确度很高(不是广告是真的)

联通4G/3G的话 IP会漫游到原归属地(没找到过相关资料是为什么)
em70 5
em70 2014-12-30 00:28:46 +08:00 via Android
是ip获取不对,还是ip归属地查询出错,高春辉搞了一个商业化IP库,据说正确率很高
w88975 6
w88975 2014-12-30 03:31:44 +08:00
@em70 ip不正确 归属地 我有接口查 可是IP都不对 很头疼