moving source to the standard trunk dir
git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@63 375186e5-ef17-0410-b0b6-91563547dcda
27
ipscan/.classpath
Executable file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="ext/rocksaw/src/java"/>
|
||||
<classpathentry kind="src" path="ext/vserv-tcpip/src/java"/>
|
||||
<classpathentry kind="src" path="resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="lib" path="ext/rocksaw/lib/tmp.jar">
|
||||
<attributes>
|
||||
<attribute value="ipscan/ext/rocksaw/lib" name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/>
|
||||
<classpathentry sourcepath="/swt/src" kind="lib" path="/swt/swt-win32.jar">
|
||||
<attributes>
|
||||
<attribute value="swt/lib" name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry sourcepath="/swt/src" kind="lib" path="/swt/swt-gtk.jar">
|
||||
<attributes>
|
||||
<attribute value="swt/lib" name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry sourcepath="ext/picocontainer/src" kind="lib" path="ext/picocontainer/picocontainer-1.0.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
20
ipscan/.project
Executable file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ipscan</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>swt</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
256
ipscan/.settings/org.eclipse.jdt.core.prefs
Executable file
@ -0,0 +1,256 @@
|
||||
#Thu Dec 14 22:09:10 EET 2006
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
|
||||
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
|
||||
org.eclipse.jdt.core.codeComplete.fieldPrefixes=
|
||||
org.eclipse.jdt.core.codeComplete.fieldSuffixes=
|
||||
org.eclipse.jdt.core.codeComplete.localPrefixes=
|
||||
org.eclipse.jdt.core.codeComplete.localSuffixes=
|
||||
org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
|
||||
org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
|
||||
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_field=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_method=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_header=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_html=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_source_code=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.comment.line_length=100
|
||||
org.eclipse.jdt.core.formatter.compact_else_if=true
|
||||
org.eclipse.jdt.core.formatter.continuation_indentation=2
|
||||
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
|
||||
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_empty_lines=false
|
||||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
|
||||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
|
||||
org.eclipse.jdt.core.formatter.indentation.size=4
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.lineSplit=120
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
|
||||
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
|
||||
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
|
||||
org.eclipse.jdt.core.formatter.tabulation.char=tab
|
||||
org.eclipse.jdt.core.formatter.tabulation.size=4
|
||||
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
|
||||
11
ipscan/.settings/org.eclipse.jdt.ui.prefs
Executable file
@ -0,0 +1,11 @@
|
||||
#Thu Dec 14 22:09:10 EET 2006
|
||||
eclipse.preferences.version=1
|
||||
formatter_profile=_Angry IP Scanner
|
||||
formatter_settings_version=10
|
||||
internal.default.compliance=user
|
||||
org.eclipse.jdt.ui.exception.name=e
|
||||
org.eclipse.jdt.ui.gettersetter.use.is=true
|
||||
org.eclipse.jdt.ui.javadoc=true
|
||||
org.eclipse.jdt.ui.keywordthis=false
|
||||
org.eclipse.jdt.ui.overrideannotation=true
|
||||
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return Returns the ${bare_field_name}.\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} The ${bare_field_name} to set.\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * ${type_name}\n *\n * @author Anton Keks\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/** */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"></template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template></templates>
|
||||
3
ipscan/.settings/org.eclipse.ltk.core.refactoring.prefs
Executable file
@ -0,0 +1,3 @@
|
||||
#Thu Jul 27 00:09:24 EEST 2006
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
|
||||
6
ipscan/.settings/org.eclipse.wst.validation.prefs
Executable file
@ -0,0 +1,6 @@
|
||||
#Thu Jul 27 00:09:24 EEST 2006
|
||||
DELEGATES_PREFERENCE=delegateValidatorListorg.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator\=org.eclipse.wst.wsdl.validation.internal.eclipse.Validator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator\=org.eclipse.wst.xsd.core.internal.validation.eclipse.Validator;
|
||||
USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPELValidator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;
|
||||
USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPELValidator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;
|
||||
USER_PREFERENCE=overrideGlobalPreferencesfalse
|
||||
eclipse.preferences.version=1
|
||||
176
ipscan/build.xml
Executable file
@ -0,0 +1,176 @@
|
||||
<?xml version="1.0"?>
|
||||
<project basedir="." name="ipscan" default="all">
|
||||
|
||||
<property name="dist" value="dist"/>
|
||||
<property name="ext" value="ext"/>
|
||||
<property name="src" value="src"/>
|
||||
<property name="resources" value="resources"/>
|
||||
<property name="test" value="test"/>
|
||||
<property name="testresults" value="testresults"/>
|
||||
|
||||
<property name="version" value="2.99a"/>
|
||||
<property name="main.class" value="net.azib.ipscan.Main"/>
|
||||
<property name="swt" value="../swt"/>
|
||||
<property name="retroguard.jar" value="${ext}/retroguard/retroguard.jar"/>
|
||||
<property name="emma.dir" value="${ext}/emma"/>
|
||||
<property name="ext.src" value="${ext}/rocksaw/src:${ext}/vserv-tcpip/src"/>
|
||||
|
||||
<taskdef name="obfuscate" classname="COM.rl.ant.RetroGuardTask" classpath="${retroguard.jar}"/>
|
||||
|
||||
<path id="emma.lib">
|
||||
<pathelement location="${emma.dir}/emma.jar" />
|
||||
<pathelement location="${emma.dir}/emma_ant.jar" />
|
||||
</path>
|
||||
|
||||
<taskdef resource="emma_ant.properties" classpathref="emma.lib"/>
|
||||
|
||||
<patternset id="classpath.resources">
|
||||
<exclude name="**/*.java"/>
|
||||
</patternset>
|
||||
|
||||
<target name="all" depends="cleanup,compile,compile-tests,test,package,cleanup_end"/>
|
||||
|
||||
<target name="all-linux" depends="cleanup,compile,compile-tests,test,package-linux,cleanup_end"/>
|
||||
|
||||
<target name="cleanup">
|
||||
<delete dir="classes-${src}"/>
|
||||
<delete dir="classes-${test}"/>
|
||||
<!--<delete dir="${testresults}"/>-->
|
||||
</target>
|
||||
|
||||
<target name="cleanup_end">
|
||||
<antcall target="cleanup"/>
|
||||
</target>
|
||||
|
||||
<macrodef name="compile">
|
||||
<attribute name="path"/>
|
||||
<attribute name="dest" default="@{path}"/>
|
||||
<attribute name="extpath" default=""/>
|
||||
<attribute name="debug" default="false"/>
|
||||
<attribute name="optimize" default="true"/>
|
||||
<sequential>
|
||||
<mkdir dir="classes-@{dest}"/>
|
||||
<javac destdir="classes-@{dest}" debug="@{debug}" source="1.4" target="1.4" optimize="@{optimize}">
|
||||
<src path="@{path}"/>
|
||||
<src path="@{extpath}"/>
|
||||
<classpath>
|
||||
<fileset dir="${ext}" includes="**/*.jar"/>
|
||||
<fileset dir="${swt}" includes="*.jar"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
<copy todir="classes-@{dest}">
|
||||
<fileset dir="@{path}">
|
||||
<patternset refid="classpath.resources"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="classes-@{dest}">
|
||||
<fileset dir="${resources}">
|
||||
<patternset refid="classpath.resources"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<target name="compile">
|
||||
<compile path="${src}" extpath="${ext.src}"/>
|
||||
</target>
|
||||
|
||||
<path id="test.path" path="classes-${test}"/>
|
||||
|
||||
<target name="compile-tests">
|
||||
<compile path="${src}" dest="${test}" extpath="${ext.src}" debug="true"/>
|
||||
<emma>
|
||||
<instr instrpathref="test.path" destdir="classes-${test}.instr" metadatafile="${testresults}/metadata.emma" merge="false" filter="net.azib.ipscan.*"/>
|
||||
</emma>
|
||||
<copy todir="classes-${test}" overwrite="true">
|
||||
<fileset dir="classes-${test}.instr" includes="**/*.class"/>
|
||||
</copy>
|
||||
<delete dir="classes-${test}.instr"/>
|
||||
<compile path="${test}" dest="${test}" debug="true"/>
|
||||
</target>
|
||||
|
||||
<target name="test">
|
||||
<delete dir="${testresults}"/>
|
||||
<mkdir dir="${testresults}"/>
|
||||
<delete file="coverage.ec"/>
|
||||
<junit haltonfailure="true" showoutput="true" dir="${basedir}" fork="on" forkmode="once">
|
||||
<jvmarg line="-Djava.library.path=${ext}/rocksaw/lib:${swt}/lib"/>
|
||||
<classpath>
|
||||
<dirset dir="classes-${test}"/>
|
||||
<fileset dir="${swt}" includes="*.jar"/>
|
||||
<path refid="emma.lib"/>
|
||||
</classpath>
|
||||
<formatter type="brief"/>
|
||||
<batchtest todir="${testresults}">
|
||||
<fileset dir="classes-${test}" includes="**/*Test.class"/>
|
||||
</batchtest>
|
||||
</junit>
|
||||
<emma>
|
||||
<report sourcepath="${src}" encoding="UTF-8">
|
||||
<fileset dir="${basedir}" includes="coverage.ec"/>
|
||||
<fileset dir="${testresults}" includes="*.emma"/>
|
||||
<txt outfile="${testresults}/coverage.txt"/>
|
||||
<html outfile="${testresults}/coverage.html"/>
|
||||
</report>
|
||||
</emma>
|
||||
</target>
|
||||
|
||||
<target name="package">
|
||||
<delete dir="${dist}"/>
|
||||
<mkdir dir="${dist}"/>
|
||||
<jar destfile="${dist}/${ant.project.name}.jar">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
<attribute name="AngryIPScanner" value="${version}"/>
|
||||
</manifest>
|
||||
<fileset dir="classes-${src}"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="package-linux">
|
||||
<delete dir="${dist}"/>
|
||||
<mkdir dir="${dist}"/>
|
||||
<unzip src="${swt}/swt-gtk.jar" dest="classes-${src}"/>
|
||||
<delete includeemptydirs="true">
|
||||
<fileset dir="classes-${src}" file="version.txt"/>
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/browser"/>
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/opengl"/>
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/internal/opengl"/>
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/internal/theme"/>
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/internal/mozilla"/>
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/internal/image">
|
||||
<include name="JPEG*"/>
|
||||
<include name="OS2*"/>
|
||||
<include name="PNG*"/>
|
||||
<include name="Png*"/>
|
||||
<include name="TIFF*"/>
|
||||
<include name="Win*"/>
|
||||
</fileset>
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/custom"/>
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/widgets">
|
||||
<include name="Cool*"/>
|
||||
<include name="Expand*"/>
|
||||
<include name="Font*"/>
|
||||
<include name="Color*"/>
|
||||
<include name="ToolBar*"/>
|
||||
<include name="ToolItem*"/>
|
||||
<include name="Tracker*"/>
|
||||
<include name="Tray*"/>
|
||||
<include name="Tree*"/>
|
||||
</fileset>
|
||||
<!-- GIJ doesn't start without this one, however Sun's java has no problems...
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/dnd"/>-->
|
||||
<fileset dir="classes-${src}/org/eclipse/swt/awt"/>
|
||||
</delete>
|
||||
<unzip src="${ext}/picocontainer/picocontainer-1.0.jar" dest="classes-${src}"/>
|
||||
<jar destfile="${dist}/${ant.project.name}.jar" >
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
<attribute name="AngryIPScanner" value="${version}"/>
|
||||
</manifest>
|
||||
<fileset dir="classes-${src}"/>
|
||||
</jar>
|
||||
<obfuscate infile="${dist}/${ant.project.name}.jar" outfile="${dist}/${ant.project.name}-obf.jar" rgsfile="${ext}/retroguard/retroguard.conf"/>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
BIN
ipscan/ext/emma/emma.jar
Executable file
BIN
ipscan/ext/emma/emma_ant.jar
Executable file
28
ipscan/ext/picocontainer/LICENSE.txt
Executable file
@ -0,0 +1,28 @@
|
||||
Copyright (c) 2003, PicoContainer Organization
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
Neither the name of the PicoContainer Organization nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
BIN
ipscan/ext/picocontainer/picocontainer-1.0.jar
Executable file
340
ipscan/ext/retroguard/GPL.txt
Executable file
@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
58
ipscan/ext/retroguard/Readme.txt
Executable file
@ -0,0 +1,58 @@
|
||||
|
||||
** RETROGUARD(tm) BYTECODE OBFUSCATOR **
|
||||
|
||||
-- RetroGuard v2.0.5, released 25th August 2005 --
|
||||
|
||||
Thank you for downloading this release of the RetroGuard
|
||||
bytecode obfuscator. If you have questions about using RetroGuard,
|
||||
or wish to report a bug to be fixed for the next release,
|
||||
please contact web@retrologic.com
|
||||
|
||||
|
||||
This software is distributed under a "dual license" model:
|
||||
|
||||
- GNU GPL for non-commercial projects and for commercial trial integration;
|
||||
|
||||
- a subscription-based commercial license for commercial projects.
|
||||
|
||||
In summary, if your project is commercial then RetroGuard is commercial;
|
||||
if your project is free software then RetroGuard is free software.
|
||||
|
||||
To obtain a license agreement for commercial use of this software,
|
||||
please visit http://www.retrologic.com/retroguard-main.html or contact
|
||||
Retrologic Systems at web@retrologic.com
|
||||
|
||||
|
||||
Included in this release are the following files and directories:
|
||||
|
||||
Readme.txt : This file.
|
||||
|
||||
GPL.txt : For non-commercial projects, RetroGuard is distributed
|
||||
under the GNU General Public License.
|
||||
-OR-
|
||||
License.txt : For commercial projects, RetroGuard is distributed under
|
||||
a subscription-based commercial license.
|
||||
|
||||
retroguard.jar : A JAR (Java ARchive) file containing the classes that
|
||||
make up the RetroGuard Bytecode Obfuscator.
|
||||
|
||||
src-dist.tar.gz: RetroGuard source files (GPL, non-commercial release only).
|
||||
|
||||
|
||||
The latest documentation for RetroGuard can be found online at:
|
||||
|
||||
http://www.retrologic.com/retroguard-docs.html
|
||||
|
||||
The change history of the software can be found at:
|
||||
|
||||
http://www.retrologic.com/retroguard-changes.html
|
||||
|
||||
Answers to common questions about obfuscation and RetroGuard can be found at:
|
||||
|
||||
http://www.retrologic.com/retroguard-faq.html
|
||||
|
||||
|
||||
If you have any questions please contact:
|
||||
|
||||
web@retrologic.com
|
||||
|
||||
13
ipscan/ext/retroguard/retroguard.conf
Executable file
@ -0,0 +1,13 @@
|
||||
.option Application
|
||||
.option MapClassString
|
||||
|
||||
.method;native ** * and_class
|
||||
|
||||
.class net/azib/ipscan/feeders/*Feeder public
|
||||
.class net/azib/ipscan/fetchers/*Fetcher public
|
||||
.class net/azib/ipscan/exporters/*Exporter public
|
||||
.class net/azib/ipscan/**/*Exception
|
||||
.class net/azib/ipscan/config/GlobalConfig public
|
||||
.class net/azib/ipscan/resources/*
|
||||
|
||||
#.class org/eclipse/swt/**/OS
|
||||
BIN
ipscan/ext/retroguard/retroguard.jar
Executable file
202
ipscan/ext/rocksaw/LICENSE
Executable file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
||||
2
ipscan/ext/rocksaw/NOTICE
Executable file
@ -0,0 +1,2 @@
|
||||
This product includes software developed by
|
||||
Daniel F. Savarese (http://www.savarese.org/).
|
||||
161
ipscan/ext/rocksaw/README
Executable file
@ -0,0 +1,161 @@
|
||||
$Id: README 6877 2006-04-14 00:56:38Z dfs $
|
||||
|
||||
=====
|
||||
ABOUT
|
||||
=====
|
||||
|
||||
RockSaw is a simple API for performing network I/O with raw
|
||||
sockets in Java.
|
||||
|
||||
|
||||
============
|
||||
REQUIREMENTS
|
||||
============
|
||||
|
||||
The 0.4.5 version of RockSaw has been compiled and tested on Linux,
|
||||
Win32 with Cygwin/MinGW/Winsock or Visual C++, and Solaris 8/9/10. It
|
||||
should compile on other POSIX systems using the GNU tool chain.
|
||||
|
||||
The Ping.java example program requires VServ TCP/IP version 0.7.x
|
||||
(http://www.savarese.org/software/vserv-tcpip.html) or later to
|
||||
compile because it uses the ICMPEchoPacket class.
|
||||
|
||||
librocksaw.so in the binary distribution is pre-compiled for Linux
|
||||
i386 and rocksaw.dll is pre-compiled for Win32 using Visual C++.
|
||||
|
||||
J2SE 1.3 or greater is required to compile because of the use of
|
||||
Runtime.addShutdownHook on Win32. If you have a need to support
|
||||
J2SE 1.2, we can find another solution for calling WSACleanup on
|
||||
Win32 platforms.
|
||||
|
||||
Winsock2 (ws2_32.dll) is required on Win32 platforms.
|
||||
|
||||
=========
|
||||
COMPILING
|
||||
=========
|
||||
|
||||
You must have the JDK_HOME environment variable set and pointing to
|
||||
the directory where the Java Development Kit is installed. Otherwise,
|
||||
the JNI headers will not be found. RockSaw has been tested primarily
|
||||
with J2SE 5 JDK 1.5, but it compiles with the J2SE 2 1.3, and 1.4
|
||||
SDKs. Only the Ping.java example program requires J2SE 5.
|
||||
|
||||
The source code requires Apache Ant (http://ant.apache.org/), GNU
|
||||
make, and GCC to compile. On Windows, you must either have Visual C++
|
||||
installed or have Cygwin and MinGW installed with support for the
|
||||
Cygwin GCC -mno-cygwin option (http://www.cygwin.com/). Autoconf
|
||||
support may be added somewhere down the line if warranted.
|
||||
|
||||
The command
|
||||
|
||||
ant -projecthelp
|
||||
|
||||
will list all build targets in build.xml. There are very few files
|
||||
in the source tree:
|
||||
|
||||
src/java Java source code
|
||||
src/jni The C JNI source and Makefile
|
||||
|
||||
When you compile the source with
|
||||
|
||||
ant jar
|
||||
|
||||
the C source will also be built by execing a call to gmake in src/jni.
|
||||
A jar file and shared library will be created and placed in the lib/
|
||||
directory. They will be called:
|
||||
|
||||
rocksaw-version.jar
|
||||
librocksaw.so
|
||||
|
||||
Currently there is no version number for the shared library. On
|
||||
Win32 systems, the shared library will be called:
|
||||
|
||||
rocksaw.dll
|
||||
|
||||
The version of Winsock linked to on Windows can be changed with
|
||||
the jni.winsock property. By default, it is set to ws2_32,
|
||||
which is Winsock2.
|
||||
|
||||
J2SE 1.4/1.3/1.2
|
||||
------------------
|
||||
|
||||
You may have to override the javac.args, javac.source, and
|
||||
javac.target properties because the -Xlint:unchecked parameter
|
||||
is only valid for J2SE 5. For example, to compile for
|
||||
J2SE 1.3:
|
||||
|
||||
ant -Djavac.args="" -Djavac.source=1.3 -Djavac.target=1.3 jar
|
||||
|
||||
Win32: CYGWIN
|
||||
-------------
|
||||
|
||||
When compiling with cygwin, you may need to redefine the jni.make
|
||||
property because it is set to "gmake" by default. Cygwin doesn't
|
||||
include a gmake executable for GNU Make. It is named only make.
|
||||
Therefore, you may have to use the following command line:
|
||||
|
||||
ant -Djni.make=make jar
|
||||
|
||||
Alternatively, you can edit the build.properties file.
|
||||
|
||||
Win32: Visual C++
|
||||
-----------------
|
||||
|
||||
To compile using Visual C++, you have to override the default
|
||||
compiler command, make command, and makefile properties:
|
||||
|
||||
jni.cc
|
||||
jni.make
|
||||
jni.makefile
|
||||
|
||||
You can override these on the command line or in build.properties.
|
||||
For example, to compile using Visual C++, you would use the
|
||||
following command:
|
||||
|
||||
ant -Djni.cc=cl -Djni.make=nmake -Djni.makefile=Makefile.win32 jar
|
||||
|
||||
Make sure your JDK_HOME environment variable is set and that
|
||||
you've run either the vcvars.bat or vsvars32.bat command
|
||||
(depending on the version of Visual C++ you're using) to set
|
||||
your paths for the command line tools.
|
||||
|
||||
Ping Example
|
||||
------------
|
||||
|
||||
The example Ping program can be compiled separately with the
|
||||
example.compile target, but requires VServ TCP/IP to compile. The
|
||||
classpath.vserv-tcpip property in build.properties must point to the
|
||||
VServ TCP/IP jar, which by default is expected to be present in the
|
||||
lib/ directory. Then you can compile the program with:
|
||||
|
||||
ant example.compile
|
||||
|
||||
|
||||
=========
|
||||
LICENSING
|
||||
=========
|
||||
|
||||
RockSaw is Copyright 2004-2005 by Daniel F. Savarese and licensed
|
||||
under the Apache License 2.0 as described in the files:
|
||||
|
||||
LICENSE
|
||||
NOTICE
|
||||
|
||||
|
||||
=====
|
||||
NOTES
|
||||
=====
|
||||
|
||||
On most operating systems, you must have root access or administrative
|
||||
privileges to use raw sockets.
|
||||
|
||||
The API is at a fairly crude stage of development (i.e., the minimum
|
||||
required to do the job it needed to do), but is functional. Don't
|
||||
hesitate to submit patches that enhance the functionality.
|
||||
|
||||
|
||||
=======
|
||||
CONTACT
|
||||
=======
|
||||
|
||||
To contact me see http://www.savarese.org/contact.html
|
||||
BIN
ipscan/ext/rocksaw/lib/librocksaw.so
Executable file
BIN
ipscan/ext/rocksaw/lib/rocksaw.dll
Executable file
BIN
ipscan/ext/rocksaw/lib/tmp.jar
Executable file
615
ipscan/ext/rocksaw/src/java/org/savarese/rocksaw/net/RawSocket.java
Executable file
@ -0,0 +1,615 @@
|
||||
/*
|
||||
* $Id: RawSocket.java 5979 2005-11-09 18:11:02Z dfs $
|
||||
*
|
||||
* Copyright 2004-2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
|
||||
package org.savarese.rocksaw.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
|
||||
/**
|
||||
* <p>The RawSocket class provides a strictly utilitarian API for
|
||||
* performing I/O with raw sockets. The API is currently crude, but
|
||||
* functional. It should evolve into something more feature-complete
|
||||
* and flexible.</p>
|
||||
*
|
||||
* <p>We throw java.io.InterruptedIOException when read/write
|
||||
* operations time out because java.net.SocketTimeoutException is
|
||||
* present only in J2SE 1.4 and up. By using InterruptedIOException,
|
||||
* we allow programmers to use the software with J2SE 1.2 and 1.3.</p>
|
||||
*
|
||||
* <p>Socket options should not be set until the socket has been
|
||||
* opened.</p>
|
||||
*
|
||||
* <p><em>Important! On most operating systems, you must have root
|
||||
* access or administrative privileges to use raw sockets.</em></p>
|
||||
*
|
||||
* @author <a href="http://www.savarese.org/">Daniel F. Savarese</a>
|
||||
*/
|
||||
|
||||
public class RawSocket {
|
||||
|
||||
/**
|
||||
* A protocol family constant for {@link #open} indicating IPv4.
|
||||
* <em>This should be moved to another class.</em>
|
||||
*/
|
||||
public static final int PF_INET = 2;
|
||||
|
||||
/**
|
||||
* A protocol family constant for {@link #open} indicating IPv6.
|
||||
* <em>This should be moved to another class.</em>
|
||||
*/
|
||||
public static final int PF_INET6 = 10 ;
|
||||
|
||||
/**
|
||||
* Initializes any system resources used by the RockSaw library.
|
||||
* Really, all it does is call WSAStartup on Win32. It may be
|
||||
* called multiple times (only the first call has any effect), but
|
||||
* each call must be matched with a corresponding call to
|
||||
* RockSawShutdown().
|
||||
*
|
||||
* @return zero if successful, otherwise some non-zero value.
|
||||
*/
|
||||
private native static int __RockSawStartup();
|
||||
|
||||
/**
|
||||
* Deallocates any system resources used by the RockSaw library.
|
||||
* Really, all it does is call WSACleanup on Win32.
|
||||
*/
|
||||
private native static void __RockSawShutdown();
|
||||
|
||||
static {
|
||||
System.loadLibrary("rocksaw");
|
||||
if(__RockSawStartup() != 0)
|
||||
throw new UnsatisfiedLinkError(__getErrorMessage());
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
public void run() {
|
||||
__RockSawShutdown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final int __UNDEFINED = -1;
|
||||
|
||||
/**
|
||||
* TimeVal is a convenience class for tracking select timeouts.
|
||||
* Should we implement select outside of this class, we can make
|
||||
* this a public top-level class with proper getters and setters.
|
||||
*/
|
||||
private static final class TimeVal {
|
||||
int seconds;
|
||||
int microseconds;
|
||||
|
||||
TimeVal() {
|
||||
seconds = microseconds = 0;
|
||||
}
|
||||
|
||||
void setInMilliseconds(int milliseconds) {
|
||||
seconds = milliseconds / 1000;
|
||||
|
||||
if(seconds > 0)
|
||||
milliseconds-=(seconds*1000);
|
||||
|
||||
microseconds = milliseconds * 1000;
|
||||
}
|
||||
|
||||
int getInMilliseconds() {
|
||||
return (seconds * 1000 + microseconds / 1000);
|
||||
}
|
||||
|
||||
boolean isZero() {
|
||||
return (seconds == 0 && microseconds == 0);
|
||||
}
|
||||
}
|
||||
|
||||
private int __socket;
|
||||
private int __family;
|
||||
private TimeVal __stimeout, __rtimeout;
|
||||
private boolean __useSelectTimeout;
|
||||
|
||||
/**
|
||||
* Creates an uninitialized socket. If the {@code os.name} system
|
||||
* property starts with the string "SunOS",
|
||||
* {@link #setUseSelectTimeout} is set to true (because Solaris does not
|
||||
* support socket send and receive timeouts), otherwise it is false
|
||||
* by default.
|
||||
*/
|
||||
public RawSocket() {
|
||||
__socket = __UNDEFINED;
|
||||
__family = __UNDEFINED;
|
||||
__stimeout = new TimeVal();
|
||||
__rtimeout = new TimeVal();
|
||||
|
||||
String os = System.getProperty("os.name");
|
||||
|
||||
if(os != null && os.startsWith("SunOS"))
|
||||
setUseSelectTimeout(true);
|
||||
else
|
||||
setUseSelectTimeout(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if the socket has been opened.
|
||||
*
|
||||
* @return True if the socket is open.
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return (__socket > 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes a system error message into a StringBuffer.
|
||||
* The message is appended to the supplied StringBuffer argument.
|
||||
* This is not a thread safe call because it relies on the value
|
||||
* of errno, which may be altered at any time by another thread.
|
||||
*
|
||||
* @param buffer The buffer in which to store the error message.
|
||||
*/
|
||||
private native static void __getErrorMessage(StringBuffer buffer);
|
||||
|
||||
private static String __getErrorMessage() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
__getErrorMessage(buf);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static void __throwIOException() throws IOException {
|
||||
throw new IOException(__getErrorMessage());
|
||||
}
|
||||
|
||||
private static void __throwSocketException() throws SocketException {
|
||||
throw new SocketException(__getErrorMessage());
|
||||
}
|
||||
|
||||
private static void __throwInterruptedIOException()
|
||||
throws InterruptedIOException
|
||||
{
|
||||
throw new InterruptedIOException(__getErrorMessage());
|
||||
}
|
||||
|
||||
private native static int __socket(int protocolFamily, int protocol);
|
||||
|
||||
|
||||
/**
|
||||
* <p>Returns the protocol number corresponding to the given protocol name.
|
||||
* For example, {@code getProtocolByName("icmp");} should return 1 and
|
||||
* {@code getProtocolByName("udp");} should return 17. The native system
|
||||
* protocol database is used to look up the protocol numbers.</p>
|
||||
*
|
||||
* <p><em>This method really belongs in another class, probably in
|
||||
* vserv-tcpip, but is currently included here as a convenience. It
|
||||
* may be moved elsewhere in the 1.0 release API.</em></p>
|
||||
*
|
||||
* @return The protocol number corresponding to the given protocol name.
|
||||
* If the protocol name cannot be found, returns a negative value.
|
||||
*/
|
||||
public native static final int getProtocolByName(String name);
|
||||
|
||||
|
||||
/**
|
||||
* Opens a raw socket.
|
||||
*
|
||||
* @param protocolFamily The protocol family of the socket (e.g.,
|
||||
* {@link #PF_INET} or {@link #PF_INET6}).
|
||||
* @param protocol The protocol within the protocol family. {@link
|
||||
* #getProtocolByName} should be used to obtain protocol numbers.
|
||||
* @exception IllegalStateException If the object instance is
|
||||
* already open.
|
||||
* @exception IOException If an error occurs while opening the socket.
|
||||
*/
|
||||
public void open(int protocolFamily, int protocol)
|
||||
throws IllegalStateException, IOException
|
||||
{
|
||||
if(isOpen())
|
||||
throw new IllegalStateException();
|
||||
__socket = __socket(protocolFamily, protocol);
|
||||
|
||||
if(__socket < 0) {
|
||||
__socket = __UNDEFINED;
|
||||
__throwIOException();
|
||||
}
|
||||
|
||||
__family = protocolFamily;
|
||||
}
|
||||
|
||||
private native static int __close(int socket);
|
||||
|
||||
/**
|
||||
* Closes the socket.
|
||||
*
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
int result = __close(__socket);
|
||||
__socket = __UNDEFINED;
|
||||
__family = __UNDEFINED;
|
||||
|
||||
if(result != 0)
|
||||
__throwIOException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if errno equals EAGAIN or EWOULDBLOCK.
|
||||
*/
|
||||
private native boolean __isErrorEAGAIN();
|
||||
|
||||
private native static int __setIPHeaderInclude(int socket, boolean on);
|
||||
|
||||
/**
|
||||
* @return A negative value if an error occurs, else zero for false and
|
||||
* a positive value for true.
|
||||
*/
|
||||
private native static int __getIPHeaderInclude(int socket);
|
||||
|
||||
|
||||
/**
|
||||
* Sets or unsets the IP_HDRINCL socket option. Setting this option
|
||||
* causes IPv4 packet writes to expect the entire IP packet,
|
||||
* starting from the header. The default behavior is to only expect
|
||||
* the data payload. This option is valid only for IPv4 sockets.
|
||||
*
|
||||
* @param on True if headers should be included, false if not.
|
||||
* @exception SocketException If the option setting could not be altered.
|
||||
*/
|
||||
public void setIPHeaderInclude(boolean on) throws SocketException {
|
||||
int result = __setIPHeaderInclude(__socket, on);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the current setting of the IP_HDRINCL option.
|
||||
*
|
||||
* @return True if the IP_HDRINCL option is set, false if not.
|
||||
* @exception SocketException If the option value could not be retrieved.
|
||||
*/
|
||||
public boolean getIPHeaderInclude() throws SocketException {
|
||||
int result = __getIPHeaderInclude(__socket);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
|
||||
return (result > 0);
|
||||
}
|
||||
|
||||
|
||||
private native static int __setSendBufferSize(int socket, int size);
|
||||
|
||||
/**
|
||||
* Sets the send buffer size (SO_SNDBUF).
|
||||
*
|
||||
* @param size The size of the send buffer.
|
||||
* @exception SocketException If the option value could not be set.
|
||||
*/
|
||||
public void setSendBufferSize(int size) throws SocketException {
|
||||
int result = __setSendBufferSize(__socket, size);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
}
|
||||
|
||||
|
||||
private native static int __getSendBufferSize(int __socket);
|
||||
|
||||
/**
|
||||
* Retrieves the send buffer size (SO_SNDBUF).
|
||||
*
|
||||
* @return The size of the send buffer.
|
||||
* @exception SocketException If the option value could not be retrieved.
|
||||
*/
|
||||
public int getSendBufferSize() throws SocketException {
|
||||
int result = __getSendBufferSize(__socket);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private native static int __setReceiveBufferSize(int socket, int size);
|
||||
|
||||
/**
|
||||
* Sets the receive buffer size (SO_RCVBUF).
|
||||
*
|
||||
* @param size The size of the receive buffer.
|
||||
* @exception SocketException If the option value could not be set.
|
||||
*/
|
||||
public void setReceiveBufferSize(int size) throws SocketException {
|
||||
int result = __setReceiveBufferSize(__socket, size);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
}
|
||||
|
||||
|
||||
private native static int __getReceiveBufferSize(int socket);
|
||||
|
||||
/**
|
||||
* Retrieves the receive buffer size (SO_RCVBUF).
|
||||
*
|
||||
* @return The size of the receive buffer.
|
||||
* @exception SocketException If the option value could not be retrieved.
|
||||
*/
|
||||
public int getReceiveBufferSize() throws SocketException {
|
||||
int result = __getReceiveBufferSize(__socket);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zero if the socket is ready for I/O, negative value if
|
||||
* timed out or error occurred.
|
||||
*/
|
||||
private native static
|
||||
int __select(int socket, boolean read, int seconds, int microseconds);
|
||||
|
||||
|
||||
/**
|
||||
* <p>Sets whether or not socket send/receive timeouts should be
|
||||
* emulated by using the POSIX {@code select} function. Not all
|
||||
* platforms support socket send/receive timeouts and this method
|
||||
* provides a means to reproduce the same effect.</p>
|
||||
*
|
||||
* <p>This method is not guaranteed to be retained in the 1.0 API. We
|
||||
* may find a better way to provide support for read/write timeouts
|
||||
* on all platforms. Technically, it's better to simply use
|
||||
* non-blocking I/O rather than rely on socket timeouts, but we have
|
||||
* yet to add a non-blocking I/O interface.</p>
|
||||
*
|
||||
* @param useSelect true if {@code select} should be used to
|
||||
* implement timeouts, false if not.
|
||||
*/
|
||||
public void setUseSelectTimeout(boolean useSelect) {
|
||||
__useSelectTimeout = useSelect;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Determines whether or not socket send/receive timeouts are
|
||||
* emulated by using the POSIX {@code select} system function.
|
||||
* Not all platforms support socket send/receive timeouts. The
|
||||
* default value is false except for platforms where the {@code
|
||||
* os.name} property starts with the string "SunOS".</p>
|
||||
*
|
||||
* @return True if send/receive timeouts are emulated with select,
|
||||
* false if not.
|
||||
*/
|
||||
public boolean getUseSelectTimeout() {
|
||||
return __useSelectTimeout;
|
||||
}
|
||||
|
||||
|
||||
private native static int __setSendTimeout(int socket, int timeout);
|
||||
|
||||
/**
|
||||
* Sets the send timeout (SO_SNDTIMEO). A timeout of zero indicates
|
||||
* an infinite timeout. A negative timeout is undefined.
|
||||
*
|
||||
* @param timeout The send timeout in milliseconds.
|
||||
* @exception SocketException If the option value could not be set.
|
||||
*/
|
||||
public void setSendTimeout(int timeout) throws SocketException {
|
||||
__stimeout.setInMilliseconds(timeout);
|
||||
|
||||
if(!getUseSelectTimeout()) {
|
||||
int result =
|
||||
__setSendTimeout(__socket, timeout);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private native static int __getSendTimeout(int socket);
|
||||
|
||||
/**
|
||||
* Retrieves the send timeout (SO_SNDTIMEO).
|
||||
*
|
||||
* @return The send timeout in milliseconds.
|
||||
* @exception SocketException If the option value could not be set.
|
||||
*/
|
||||
public int getSendTimeout() throws SocketException {
|
||||
int result;
|
||||
|
||||
if(getUseSelectTimeout())
|
||||
result = __stimeout.getInMilliseconds();
|
||||
else {
|
||||
result = __getSendTimeout(__socket);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private native static int __setReceiveTimeout(int socket, int timeout);
|
||||
|
||||
/**
|
||||
* Sets the receive timeout (SO_RCVTIMEO). A timeout of zero indicates
|
||||
* an infinite timeout. A negative timeout is undefined.
|
||||
*
|
||||
* @param timeout The receive timeout in milliseconds.
|
||||
* @exception SocketException If the option value could not be set.
|
||||
*/
|
||||
public void setReceiveTimeout(int timeout) throws SocketException {
|
||||
__rtimeout.setInMilliseconds(timeout);
|
||||
|
||||
if(!getUseSelectTimeout()) {
|
||||
int result =
|
||||
__setReceiveTimeout(__socket, timeout);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private native static int __getReceiveTimeout(int socket);
|
||||
|
||||
/**
|
||||
* Retrieves the receive timeout (SO_RCVTIMEO).
|
||||
*
|
||||
* @return The receive timeout in milliseconds.
|
||||
* @exception SocketException If the option value could not be set.
|
||||
*/
|
||||
public int getReceiveTimeout() throws SocketException {
|
||||
int result;
|
||||
|
||||
if(getUseSelectTimeout())
|
||||
result = __rtimeout.getInMilliseconds();
|
||||
else {
|
||||
result = __getReceiveTimeout(__socket);
|
||||
|
||||
if(result < 0)
|
||||
__throwSocketException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private native static int __recvfrom(int socket, byte[] data, int offset,
|
||||
int length, int family, byte[] address);
|
||||
|
||||
/**
|
||||
* Reads packet data from the socket. IPv4 ({@link #PF_INET})
|
||||
* packets will be delivered in their entirety, including the IP
|
||||
* header. IPv6 ({@link #PF_INET6}) packet data will not include
|
||||
* the IPV6 header.
|
||||
*
|
||||
* @param address The source to read from.
|
||||
* @param data The buffer in which to store the packet data.
|
||||
* @param offset The offset into the buffer where the data should
|
||||
* be stored.
|
||||
* @param length The number of bytes to read.
|
||||
* @exception IllegalArgumentException If the offset or lengths are invalid.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception InterruptedIOException If the read operation times out.
|
||||
* @return The number of bytes read.
|
||||
*/
|
||||
public int read(InetAddress address, byte[] data, int offset,
|
||||
int length)
|
||||
throws IllegalArgumentException, IOException, InterruptedIOException
|
||||
{
|
||||
if(offset < 0 || length < 0 || length > data.length - offset)
|
||||
throw new IllegalArgumentException("Invalid offset or length.");
|
||||
|
||||
int result = 0;
|
||||
|
||||
if(getUseSelectTimeout() && !__rtimeout.isZero())
|
||||
result =
|
||||
__select(__socket, true, __rtimeout.seconds, __rtimeout.microseconds);
|
||||
//System.out.println("s" + System.currentTimeMillis());
|
||||
|
||||
// ??? setsockopt(ssock, IPPROTO_IP, IP_HDRINCL, (char *)&bOpt, sizeof(bOpt));
|
||||
|
||||
if(result == 0)
|
||||
result =
|
||||
__recvfrom(__socket, data, offset, length, __family,
|
||||
address.getAddress());
|
||||
//System.out.println("e" + System.currentTimeMillis());
|
||||
|
||||
if(result < 0) {
|
||||
if(__isErrorEAGAIN())
|
||||
__throwInterruptedIOException();
|
||||
else
|
||||
__throwIOException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/** Same as {@code read(address, data, 0, data.length);} */
|
||||
public int read(InetAddress address, byte[] data)
|
||||
throws IOException, InterruptedIOException
|
||||
{
|
||||
return read(address, data, 0, data.length);
|
||||
}
|
||||
|
||||
|
||||
private native static int __sendto(int socket, byte[] data, int offset,
|
||||
int length, int family, byte[] address);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Writes packet data to the socket. The data should not include
|
||||
* the IP header. IPv4 ({@link #PF_INET}) sockets may set the
|
||||
* IP_HDRINCL option with {@link #setIPHeaderInclude}, in which case the
|
||||
* packet data should include the IP header.
|
||||
*
|
||||
* @param address The destination to write to.
|
||||
* @param data The buffer from which to copy the packet data.
|
||||
* @param offset The offset into the buffer where the data starts.
|
||||
* @param length The number of bytes to write.
|
||||
* @exception IllegalArgumentException If the offset or lengths are invalid.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception InterruptedIOException If the write operation times out.
|
||||
* @return The number of bytes written.
|
||||
*/
|
||||
public int write(InetAddress address, byte[] data, int offset, int length)
|
||||
throws IllegalArgumentException, IOException, InterruptedIOException
|
||||
{
|
||||
if(offset < 0 || length < 0 || length > data.length - offset)
|
||||
throw new IllegalArgumentException("Invalid offset or length.");
|
||||
|
||||
int result = 0;
|
||||
|
||||
if(getUseSelectTimeout() && !__stimeout.isZero())
|
||||
result =
|
||||
__select(__socket, false, __stimeout.seconds, __stimeout.microseconds);
|
||||
|
||||
if(result == 0)
|
||||
result =
|
||||
__sendto(__socket, data, offset, length, __family,
|
||||
address.getAddress());
|
||||
|
||||
if(result < 0) {
|
||||
if(__isErrorEAGAIN())
|
||||
__throwInterruptedIOException();
|
||||
else
|
||||
__throwIOException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/** Same as {@code write(address, data, 0, data.length);} */
|
||||
public int write(InetAddress address, byte[] data)
|
||||
throws IOException, InterruptedIOException
|
||||
{
|
||||
return write(address, data, 0, data.length);
|
||||
}
|
||||
|
||||
}
|
||||
74
ipscan/ext/rocksaw/src/jni/Makefile
Executable file
@ -0,0 +1,74 @@
|
||||
#
|
||||
# $Id: Makefile 6875 2006-04-14 00:29:33Z dfs $
|
||||
#
|
||||
# Copyright 2004-2005 Daniel F. Savarese
|
||||
# Contact Information: http://www.savarese.org/contact.html
|
||||
#
|
||||
# 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.savarese.org/software/ApacheLicense-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.
|
||||
#
|
||||
|
||||
UNAME := $(shell uname)
|
||||
CYGWIN := $(findstring CYGWIN,$(UNAME))
|
||||
DARWIN := $(findstring Darwin,$(UNAME))
|
||||
|
||||
ifeq ($(CYGWIN),CYGWIN)
|
||||
JDK_HOME := $(shell cygpath $(JDK_HOME))
|
||||
endif
|
||||
|
||||
JAVA_INCDIR = $(JDK_HOME)/include
|
||||
JAVA_INCDIR_PLAF = $(dir $(wildcard $(JAVA_INCDIR)/*/jni_md.h))
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -ansi -Wall -O2 -pipe
|
||||
CPPFLAGS = -I$(JAVA_INCDIR) -I$(JAVA_INCDIR_PLAF)
|
||||
WINSOCK = ws2_32
|
||||
LDFLAGS =
|
||||
|
||||
ifeq ($(CYGWIN),CYGWIN)
|
||||
override CC += -mno-cygwin
|
||||
CPPFLAGS += -D__int64="long long"
|
||||
LIBNAME = rocksaw
|
||||
LIBEXTENSION = dll
|
||||
LDFLAGS += -Wl,--kill-at -l$(WINSOCK)
|
||||
else
|
||||
LIBNAME = librocksaw
|
||||
|
||||
ifeq ($(DARWIN),Darwin)
|
||||
LIBEXTENSION = jnilib
|
||||
LDFLAGS += -dynamiclib -noprebind -single_module
|
||||
else
|
||||
CFLAGS += -fpic
|
||||
LIBEXTENSION = so
|
||||
endif
|
||||
endif
|
||||
|
||||
SRC := $(shell find . -name "*.c" -print)
|
||||
OBJ := $(SRC:%.c=%.o)
|
||||
|
||||
CLEAN_EXTENSIONS = o $(LIBEXTENSION)
|
||||
|
||||
LIBROCKSAW = $(LIBNAME).$(LIBEXTENSION)
|
||||
|
||||
all: $(LIBROCKSAW)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(LIBROCKSAW): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
for extension in $(CLEAN_EXTENSIONS); do \
|
||||
find . -name "*.$$extension" | xargs rm -f ; \
|
||||
done
|
||||
find . -name "*~" | xargs rm -f
|
||||
46
ipscan/ext/rocksaw/src/jni/Makefile.win32
Executable file
@ -0,0 +1,46 @@
|
||||
#
|
||||
# $Id: Makefile.win32 5253 2005-05-06 04:24:20Z dfs $
|
||||
#
|
||||
# Copyright 2004-2005 Daniel F. Savarese
|
||||
# Contact Information: http://www.savarese.org/contact.html
|
||||
#
|
||||
# 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.savarese.org/software/ApacheLicense-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.
|
||||
#
|
||||
|
||||
JAVA_INCDIR = $(JDK_HOME)\include
|
||||
JAVA_INCDIR_PLAF = $(JAVA_INCDIR)\win32
|
||||
|
||||
CC = cl
|
||||
CFLAGS = -TC
|
||||
CPPFLAGS = -I$(JAVA_INCDIR) -I$(JAVA_INCDIR_PLAF)
|
||||
WINSOCK = ws2_32
|
||||
LDFLAGS = $(WINSOCK).lib
|
||||
|
||||
SRC = RawSocket.c
|
||||
OBJ = $(SRC:.c=.obj)
|
||||
|
||||
LIBNAME = rocksaw
|
||||
LIBEXTENSION = dll
|
||||
LIBROCKSAW = $(LIBNAME).$(LIBEXTENSION)
|
||||
CLEAN_EXTENSIONS = *.obj *.$(LIBEXTENSION) *.lib *.exp
|
||||
|
||||
all: $(LIBROCKSAW)
|
||||
|
||||
.c.obj:
|
||||
$(CC) -nologo $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(LIBROCKSAW): $(OBJ)
|
||||
$(CC) -nologo -MD -LD -o $@ $** $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
del $(CLEAN_EXTENSIONS)
|
||||
516
ipscan/ext/rocksaw/src/jni/RawSocket.c
Executable file
@ -0,0 +1,516 @@
|
||||
/*
|
||||
* $Id: RawSocket.c 5982 2005-11-09 18:20:21Z dfs $
|
||||
*
|
||||
* Copyright 2004-2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
|
||||
# if !defined(close)
|
||||
# define close(fd) closesocket(fd)
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
# include <netdb.h>
|
||||
# include <netinet/in.h>
|
||||
# include <sys/socket.h>
|
||||
# include <unistd.h>
|
||||
# include <sys/time.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "RawSocket.h"
|
||||
|
||||
/*
|
||||
* Utility functions.
|
||||
*/
|
||||
|
||||
static int setintsockopt(int socket, int level, int option, int value);
|
||||
static int getintsockopt(int socket, int level, int option);
|
||||
static int settimeout(int socket, int option, int timeout);
|
||||
static int gettimeout(int socket, int option);
|
||||
|
||||
static int setintsockopt(int socket, int level, int option, int value) {
|
||||
return setsockopt(socket, level, option, (void*)&value, sizeof(value));
|
||||
}
|
||||
|
||||
|
||||
static int getintsockopt(int socket, int level, int option) {
|
||||
int value = -1;
|
||||
socklen_t size = sizeof(value);
|
||||
int result = getsockopt(socket, level, option, (void*)&value, &size);
|
||||
|
||||
if(result < 0)
|
||||
return result;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
static int settimeout(int socket, int option, int timeout) {
|
||||
#if defined(_WIN32)
|
||||
return setintsockopt(socket, SOL_SOCKET, option, timeout);
|
||||
#else
|
||||
int seconds;
|
||||
struct timeval value;
|
||||
|
||||
seconds = timeout / 1000;
|
||||
|
||||
if(seconds > 0)
|
||||
timeout-=(seconds*1000);
|
||||
|
||||
value.tv_sec = seconds;
|
||||
value.tv_usec = timeout * 1000;
|
||||
|
||||
return setsockopt(socket, SOL_SOCKET, option, (void*)&value, sizeof(value));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int gettimeout(int socket, int option) {
|
||||
int result;
|
||||
struct timeval value;
|
||||
socklen_t size = sizeof(value);
|
||||
|
||||
result = getsockopt(socket, SOL_SOCKET, option, (void*)&value, &size);
|
||||
|
||||
if(result < 0)
|
||||
return result;
|
||||
|
||||
return (value.tv_sec * 1000 + value.tv_usec / 1000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __RockSawInit();
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1RockSawStartup
|
||||
(JNIEnv *env, jclass cls)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
WORD version = MAKEWORD(2, 0);
|
||||
WSADATA data;
|
||||
return (errno = WSAStartup(version, &data));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __RockSawShutdown();
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1RockSawShutdown
|
||||
(JNIEnv *env, jclass cls)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __getErrorMessage
|
||||
* Signature: (Ljava/lang/StringBuffer;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getErrorMessage
|
||||
(JNIEnv *env, jclass cls, jobject buffer)
|
||||
{
|
||||
jclass sbc;
|
||||
jstring str;
|
||||
jmethodID mid;
|
||||
|
||||
if(errno) {
|
||||
char *message = NULL;
|
||||
|
||||
#if defined(_WIN32)
|
||||
int formatted =
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, errno,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) &message, 0, NULL );
|
||||
if(!formatted)
|
||||
message = strerror(errno);
|
||||
#else
|
||||
message = strerror(errno);
|
||||
#endif
|
||||
|
||||
str = (*env)->NewStringUTF(env, message);
|
||||
|
||||
#if defined(_WIN32)
|
||||
if(formatted)
|
||||
LocalFree(message);
|
||||
#endif
|
||||
|
||||
sbc = (*env)->GetObjectClass(env, buffer);
|
||||
mid =
|
||||
(*env)->GetMethodID(env, sbc, "append",
|
||||
"(Ljava/lang/String;)Ljava/lang/StringBuffer;");
|
||||
(*env)->CallObjectMethod(env, buffer, mid, str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __select
|
||||
* Signature: (IZII)I
|
||||
*
|
||||
* Returns zero if the socket is ready for I/O.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1select
|
||||
(JNIEnv *env, jclass cls,
|
||||
jint socket, jboolean read, jint seconds, jint microseconds)
|
||||
{
|
||||
int result;
|
||||
struct timeval timeout;
|
||||
fd_set *rset = NULL, *wset = NULL, errset, fdset;
|
||||
|
||||
FD_ZERO(&fdset);
|
||||
FD_ZERO(&errset);
|
||||
FD_SET(socket, &fdset);
|
||||
FD_SET(socket, &errset);
|
||||
|
||||
timeout.tv_sec = seconds;
|
||||
timeout.tv_usec = microseconds;
|
||||
|
||||
if(read)
|
||||
rset = &fdset;
|
||||
else
|
||||
wset = &fdset;
|
||||
|
||||
result = select(socket + 1, rset, wset, &errset, &timeout);
|
||||
|
||||
if(result >= 0) {
|
||||
if(FD_ISSET(socket, &errset))
|
||||
result = -1;
|
||||
else if(FD_ISSET(socket, &fdset))
|
||||
result = 0;
|
||||
else {
|
||||
#if defined(_WIN32)
|
||||
errno = WSAETIMEDOUT;
|
||||
#else
|
||||
errno = EAGAIN;
|
||||
#endif
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __socket
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1socket
|
||||
(JNIEnv *env, jclass cls, jint family, jint protocol)
|
||||
{
|
||||
return socket(family, SOCK_RAW, protocol);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: getProtocolByName
|
||||
* Signature: (Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket_getProtocolByName
|
||||
(JNIEnv *env, jclass cls, jstring name)
|
||||
{
|
||||
const char *utf = (*env)->GetStringUTFChars(env, name, NULL);
|
||||
struct protoent *proto = getprotobyname(utf);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, name, utf);
|
||||
|
||||
return proto->p_proto;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __close
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1close
|
||||
(JNIEnv *env, jclass cls, jint socket)
|
||||
{
|
||||
return close(socket);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __recvfrom
|
||||
* Signature: (I[BIII[B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1recvfrom
|
||||
(JNIEnv *env, jclass cls, jint socket,
|
||||
jbyteArray data, jint offset, jint len, jint family, jbyteArray address)
|
||||
{
|
||||
int result;
|
||||
jbyte *buf;
|
||||
struct sockaddr *saddr;
|
||||
struct sockaddr_in sin;
|
||||
socklen_t socklen;
|
||||
|
||||
/* We support only IPv4 for now. There's a better way to handle
|
||||
* this, using getaddrinfo if we only allow receives from a preset
|
||||
* host, obviating the need to check the protocol family and recreate
|
||||
* the required sockaddr.
|
||||
*/
|
||||
if(family == PF_INET) {
|
||||
socklen = sizeof(sin);
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = PF_INET;
|
||||
buf = (*env)->GetByteArrayElements(env, address, NULL);
|
||||
memcpy(&sin.sin_addr, buf, sizeof(sin.sin_addr));
|
||||
(*env)->ReleaseByteArrayElements(env, address, buf, JNI_ABORT);
|
||||
saddr = (struct sockaddr *)&sin;
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
return errno;
|
||||
}
|
||||
|
||||
buf = (*env)->GetByteArrayElements(env, data, NULL);
|
||||
|
||||
result = recvfrom(socket, buf+offset, len, 0, saddr, &socklen);
|
||||
|
||||
(*env)->ReleaseByteArrayElements(env, data, buf, 0);
|
||||
|
||||
#if defined(_WIN32)
|
||||
if(result < 0)
|
||||
errno = WSAGetLastError();
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __sendto
|
||||
* Signature: (I[BIII[B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1sendto
|
||||
(JNIEnv *env, jclass cls, jint socket,
|
||||
jbyteArray data, jint offset, jint len, jint family, jbyteArray address)
|
||||
{
|
||||
int result;
|
||||
jbyte *buf;
|
||||
struct sockaddr *saddr;
|
||||
struct sockaddr_in sin;
|
||||
socklen_t socklen;
|
||||
|
||||
/* We only support IPv4 for now. There's a better way to handle
|
||||
* this, using getaddrinfo if we only allow receives from a preset
|
||||
* host, obviating the need to check the protocol family and recreate
|
||||
* the required sockaddr.
|
||||
*/
|
||||
if(family == PF_INET) {
|
||||
socklen = sizeof(sin);
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = PF_INET;
|
||||
buf = (*env)->GetByteArrayElements(env, address, NULL);
|
||||
memcpy(&sin.sin_addr, buf, sizeof(sin.sin_addr));
|
||||
(*env)->ReleaseByteArrayElements(env, address, buf, JNI_ABORT);
|
||||
saddr = (struct sockaddr *)&sin;
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
return errno;
|
||||
}
|
||||
|
||||
buf = (*env)->GetByteArrayElements(env, data, NULL);
|
||||
|
||||
result = sendto(socket, buf+offset, len, 0, saddr, socklen);
|
||||
|
||||
(*env)->ReleaseByteArrayElements(env, data, buf, JNI_ABORT);
|
||||
|
||||
#if defined(_WIN32)
|
||||
if(result < 0)
|
||||
errno = WSAGetLastError();
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __isErrorEAGAIN
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1isErrorEAGAIN
|
||||
(JNIEnv *env, jclass cls)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return (errno == WSAETIMEDOUT);
|
||||
#else
|
||||
return (errno == EAGAIN || errno == EWOULDBLOCK);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __setIPHeaderInclude
|
||||
* Signature: (IZ)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setIPHeaderInclude
|
||||
(JNIEnv *env, jclass cls, jint socket, jboolean on)
|
||||
{
|
||||
return setintsockopt(socket, IPPROTO_IP, IP_HDRINCL, on);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __getIPHeaderInclude
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getIPHeaderInclude
|
||||
(JNIEnv *env, jclass cls, jint socket)
|
||||
{
|
||||
return getintsockopt(socket, IPPROTO_IP, IP_HDRINCL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __setSendBufferSize
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setSendBufferSize
|
||||
(JNIEnv *env, jclass cls, jint socket, jint size)
|
||||
{
|
||||
return setintsockopt(socket, SOL_SOCKET, SO_SNDBUF, size);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __getSendBufferSize
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getSendBufferSize
|
||||
(JNIEnv *env, jclass cls, jint socket)
|
||||
{
|
||||
return getintsockopt(socket, SOL_SOCKET, SO_SNDBUF);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __setReceiveBufferSize
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setReceiveBufferSize
|
||||
(JNIEnv *env, jclass cls, jint socket, jint size)
|
||||
{
|
||||
return setintsockopt(socket, SOL_SOCKET, SO_RCVBUF, size);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __getReceiveBufferSize
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getReceiveBufferSize
|
||||
(JNIEnv *env, jclass cls, jint socket)
|
||||
{
|
||||
return getintsockopt(socket, SOL_SOCKET, SO_RCVBUF);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __setSendTimeout
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setSendTimeout
|
||||
(JNIEnv *env, jclass cls, jint socket, jint timeout)
|
||||
{
|
||||
return settimeout(socket, SO_SNDTIMEO, timeout);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __getSendTimeout
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getSendTimeout
|
||||
(JNIEnv *env, jclass cls, jint socket)
|
||||
{
|
||||
return gettimeout(socket, SO_SNDTIMEO);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __setReceiveTimeout
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setReceiveTimeout
|
||||
(JNIEnv *env, jclass cls, jint socket, jint timeout)
|
||||
{
|
||||
return settimeout(socket, SO_RCVTIMEO, timeout);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_savarese_rocksaw_net_RawSocket
|
||||
* Method: __getReceiveTimeout
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getReceiveTimeout
|
||||
(JNIEnv *env, jclass cls, jint socket)
|
||||
{
|
||||
return gettimeout(socket, SO_RCVTIMEO);
|
||||
}
|
||||
112
ipscan/ext/rocksaw/src/jni/RawSocket.h
Executable file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* $Id: RawSocket.h 5979 2005-11-09 18:11:02Z dfs $
|
||||
*
|
||||
* Copyright 2004-2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
#ifndef __ROCKSAW_RAW_SOCKET_H
|
||||
#define __ROCKSAW_RAW_SOCKET_H
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getErrorMessage
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1RockSawStartup
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1RockSawShutdown
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1select
|
||||
(JNIEnv *env, jclass cls, jint, jboolean, jint, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1socket
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket_getProtocolByName
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1close
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1recvfrom
|
||||
(JNIEnv *, jclass, jint, jbyteArray, jint, jint, jint, jbyteArray);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1sendto
|
||||
(JNIEnv *, jclass, jint, jbyteArray, jint, jint, jint, jbyteArray);
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1isErrorEAGAIN
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setIPHeaderInclude
|
||||
(JNIEnv *, jclass, jint, jboolean);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getIPHeaderInclude
|
||||
(JNIEnv *env, jclass cls, jint socket);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setSendBufferSize
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getSendBufferSize
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setReceiveBufferSize
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getReceiveBufferSize
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setSendTimeout
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getSendTimeout
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1setReceiveTimeout
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_savarese_rocksaw_net_RawSocket__1_1getReceiveTimeout
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
202
ipscan/ext/vserv-tcpip/LICENSE
Executable file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
||||
2
ipscan/ext/vserv-tcpip/NOTICE
Executable file
@ -0,0 +1,2 @@
|
||||
This product includes software developed by
|
||||
Daniel F. Savarese (http://www.savarese.org/).
|
||||
57
ipscan/ext/vserv-tcpip/README
Executable file
@ -0,0 +1,57 @@
|
||||
$Id: README 6024 2005-12-10 23:04:56Z dfs $
|
||||
|
||||
ABOUT
|
||||
-----
|
||||
|
||||
Virtual Services TCP/IP, or VServ TCP/IP for short, is a Java library that
|
||||
enables you to easily manipulate IP and TCP packets. It is intended for
|
||||
use in conjunction with a library which generates packets, such as
|
||||
VServ IPQ, as byte arrays. At the moment it supports only IPv4 packet
|
||||
manipulation.
|
||||
|
||||
The API is still in flux; some methods are missing and some existing
|
||||
methods will likely be renamed. If you would like something added,
|
||||
please submit a patch in unified diff format.
|
||||
|
||||
|
||||
REQUIREMENTS
|
||||
------------
|
||||
|
||||
VServ TCP/IP requires J2SE 1.4 or greater to compile and run.
|
||||
|
||||
|
||||
COMPILING
|
||||
---------
|
||||
|
||||
The source code requires Apache Ant (http://ant.apache.org/) to compile.
|
||||
|
||||
ant -projecthelp
|
||||
|
||||
will list all build targets in build.xml. There are very few files
|
||||
in the source tree:
|
||||
|
||||
src/java Java source code
|
||||
|
||||
When you compile the source with
|
||||
|
||||
ant jar
|
||||
|
||||
the following jar file will be created and placed in the lib/ directory:
|
||||
|
||||
vserv-tcpip-version.jar
|
||||
|
||||
|
||||
LICENSING
|
||||
---------
|
||||
|
||||
VServ TCP/IP is Copyright 2004-2005 by Daniel F. Savarese and licensed
|
||||
under the Apache License 2.0 as described in the files:
|
||||
|
||||
LICENSE
|
||||
NOTICE
|
||||
|
||||
|
||||
CONTACT
|
||||
-------
|
||||
|
||||
To contact me see http://www.savarese.org/contact.html
|
||||
102
ipscan/ext/vserv-tcpip/src/java/org/savarese/vserv/tcpip/ICMPEchoPacket.java
Executable file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* $Id: ICMPEchoPacket.java 5260 2005-05-10 21:01:16Z dfs $
|
||||
*
|
||||
* Copyright 2004-2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
|
||||
package org.savarese.vserv.tcpip;
|
||||
|
||||
/**
|
||||
* ICMPEchoPacket extends {@link ICMPPacket} to implement ICMP echo request
|
||||
* and reply packets.
|
||||
*
|
||||
* @author <a href="http://www.savarese.org/">Daniel F. Savarese</a>
|
||||
*/
|
||||
|
||||
public class ICMPEchoPacket extends ICMPPacket {
|
||||
|
||||
/** Offset into the ICMP packet of the identifier header value. */
|
||||
public static final int OFFSET_IDENTIFIER = 4;
|
||||
|
||||
/** Offset into the ICMP packet of the sequence number header value. */
|
||||
public static final int OFFSET_SEQUENCE = 6;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ICMP echo packet of a given size.
|
||||
*
|
||||
* @param size The number of bytes in the packet.
|
||||
*/
|
||||
public ICMPEchoPacket(int size) {
|
||||
super(size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ICMP echo packet that is a copy of a given packet.
|
||||
*
|
||||
* @param packet The packet to replicate.
|
||||
*/
|
||||
public ICMPEchoPacket(ICMPEchoPacket packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
|
||||
public int getICMPHeaderByteLength() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the identifier header field.
|
||||
*
|
||||
* @param id The new identifier.
|
||||
*/
|
||||
public final void setIdentifier(int id) {
|
||||
_data_[_offset + OFFSET_IDENTIFIER] = (byte)((id >> 8) & 0xff);
|
||||
_data_[_offset + OFFSET_IDENTIFIER + 1] = (byte)(id & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The identifier header field.
|
||||
*/
|
||||
public final int getIdentifier() {
|
||||
return (((_data_[_offset + OFFSET_IDENTIFIER] & 0xff) << 8) |
|
||||
(_data_[_offset + OFFSET_IDENTIFIER + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the sequence number.
|
||||
*
|
||||
* @param seq The new sequence number.
|
||||
*/
|
||||
public final void setSequenceNumber(int seq) {
|
||||
_data_[_offset + OFFSET_SEQUENCE] = (byte)((seq >> 8) & 0xff);
|
||||
_data_[_offset + OFFSET_SEQUENCE + 1] = (byte)(seq & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The sequence number.
|
||||
*/
|
||||
public final int getSequenceNumber() {
|
||||
return (((_data_[_offset + OFFSET_SEQUENCE] & 0xff) << 8) |
|
||||
(_data_[_offset + OFFSET_SEQUENCE + 1] & 0xff));
|
||||
}
|
||||
|
||||
}
|
||||
227
ipscan/ext/vserv-tcpip/src/java/org/savarese/vserv/tcpip/ICMPPacket.java
Executable file
@ -0,0 +1,227 @@
|
||||
/*
|
||||
* $Id: ICMPPacket.java 5347 2005-05-25 22:45:54Z dfs $
|
||||
*
|
||||
* Copyright 2004-2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
|
||||
package org.savarese.vserv.tcpip;
|
||||
|
||||
/**
|
||||
* ICMPPacket extends {@link IPPacket} to handle ICMP packets. The ICMP
|
||||
* packet structure is described in
|
||||
* <a href="http://www.ietf.org/rfc/rfc0792.txt?number=792">RFC 792</a>.
|
||||
*
|
||||
* @author <a href="http://www.savarese.org/">Daniel F. Savarese</a>
|
||||
*/
|
||||
|
||||
public abstract class ICMPPacket extends IPPacket {
|
||||
|
||||
/** Offset into the ICMP packet of the type header value. */
|
||||
public static final int OFFSET_TYPE = 0;
|
||||
|
||||
/** Offset into the ICMP packet of the code header value. */
|
||||
public static final int OFFSET_CODE = 1;
|
||||
|
||||
/** Offset into the ICMP packet of the ICMP checksum. */
|
||||
public static final int OFFSET_ICMP_CHECKSUM = 2;
|
||||
|
||||
/** Offset into the ICMP packet of the identifier header value. */
|
||||
public static final int OFFSET_IDENTIFIER = 4;
|
||||
|
||||
/** Offset into the ICMP packet of the sequence number header value. */
|
||||
public static final int OFFSET_SEQUENCE = 6;
|
||||
|
||||
/** The ICMP type number for an echo request. */
|
||||
public static final int TYPE_ECHO_REQUEST = 8;
|
||||
|
||||
/** The ICMP type number for an echo reply. */
|
||||
public static final int TYPE_ECHO_REPLY = 0;
|
||||
|
||||
/** The ICMP type number for an "host unreachable" message. */
|
||||
public static final int TYPE_HOST_UNREACHABLE = 3;
|
||||
|
||||
/** The byte offset into the IP packet where the ICMP packet begins. */
|
||||
int _offset;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ICMP packet of a given size.
|
||||
*
|
||||
* @param size The number of bytes in the packet.
|
||||
*/
|
||||
public ICMPPacket(int size) {
|
||||
super(size);
|
||||
_offset = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new ICMP packet that is a copy of a given packet.
|
||||
*
|
||||
* @param packet The packet to replicate.
|
||||
*/
|
||||
public ICMPPacket(ICMPPacket packet) {
|
||||
super(packet.size());
|
||||
copy(packet);
|
||||
_offset = packet._offset;
|
||||
}
|
||||
|
||||
|
||||
/** @return The number of bytes in the ICMP packet header. */
|
||||
public abstract int getICMPHeaderByteLength();
|
||||
|
||||
|
||||
public void setIPHeaderLength(int length) {
|
||||
super.setIPHeaderLength(length);
|
||||
_offset = getIPHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The total number of bytes in the IP and ICMP headers.
|
||||
*/
|
||||
public final int getCombinedHeaderByteLength() {
|
||||
return _offset + getICMPHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the length of the ICMP data payload.
|
||||
*
|
||||
* @param length The length of the ICMP data payload in bytes.
|
||||
*/
|
||||
public final void setICMPDataByteLength(int length) {
|
||||
if(length < 0)
|
||||
length = 0;
|
||||
|
||||
setIPPacketLength(getCombinedHeaderByteLength() + length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The number of bytes in the ICMP data payload.
|
||||
*/
|
||||
public final int getICMPDataByteLength() {
|
||||
return getIPPacketLength() - getCombinedHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The ICMP packet length. This is the size of the IP packet
|
||||
* minus the size of the IP header.
|
||||
*/
|
||||
public final int getICMPPacketByteLength() {
|
||||
return getIPPacketLength() - _offset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the contents of an ICMPPacket. If the current data array is
|
||||
* of insufficient length to store the contents, a new array is
|
||||
* allocated.
|
||||
*
|
||||
* @param packet The TCPPacket to copy.
|
||||
*/
|
||||
public final void copyData(ICMPPacket packet) {
|
||||
if(_data_.length < packet._data_.length) {
|
||||
byte[] data = new byte[packet._data_.length];
|
||||
System.arraycopy(_data_, 0, data, 0, getCombinedHeaderByteLength());
|
||||
_data_ = data;
|
||||
}
|
||||
int length = packet.getICMPDataByteLength();
|
||||
System.arraycopy(packet._data_, packet.getCombinedHeaderByteLength(),
|
||||
_data_, getCombinedHeaderByteLength(), length);
|
||||
setICMPDataByteLength(length);
|
||||
}
|
||||
|
||||
|
||||
public void setData(byte[] data) {
|
||||
super.setData(data);
|
||||
_offset = getIPHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the ICMP type header field.
|
||||
*
|
||||
* @param type The new type.
|
||||
*/
|
||||
public final void setType(int type) {
|
||||
_data_[_offset + OFFSET_TYPE] = (byte)(type & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The ICMP type header field.
|
||||
*/
|
||||
public final int getType() {
|
||||
return (_data_[_offset + OFFSET_TYPE] & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the ICMP code header field.
|
||||
*
|
||||
* @param code The new type.
|
||||
*/
|
||||
public final void setCode(int code) {
|
||||
_data_[_offset + OFFSET_CODE] = (byte)(code & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The ICMP code header field.
|
||||
*/
|
||||
public final int getCode() {
|
||||
return (_data_[_offset + OFFSET_CODE] & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The ICMP checksum.
|
||||
*/
|
||||
public final int getICMPChecksum() {
|
||||
return (((_data_[_offset + OFFSET_ICMP_CHECKSUM] & 0xff) << 8) |
|
||||
(_data_[_offset + OFFSET_ICMP_CHECKSUM + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the ICMP checksum, optionally updating the ICMP checksum header.
|
||||
*
|
||||
* @param update Specifies whether or not to update the ICMP checksum
|
||||
* header after computing the checksum. A value of true indicates
|
||||
* the header should be updated, a value of false indicates it
|
||||
* should not be updated.
|
||||
* @return The computed ICMP checksum.
|
||||
*/
|
||||
public final int computeICMPChecksum(boolean update) {
|
||||
return _computeChecksum_(_offset, _offset + OFFSET_ICMP_CHECKSUM,
|
||||
getIPPacketLength(), 0, update);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>computeICMPChecksum(true);</code>
|
||||
*
|
||||
* @return The computed ICMP checksum value.
|
||||
*/
|
||||
public final int computeICMPChecksum() {
|
||||
return computeICMPChecksum(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
527
ipscan/ext/vserv-tcpip/src/java/org/savarese/vserv/tcpip/IPPacket.java
Executable file
@ -0,0 +1,527 @@
|
||||
/*
|
||||
* $Id: IPPacket.java 6025 2005-12-10 23:21:25Z dfs $
|
||||
*
|
||||
* Copyright 2004-2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
|
||||
package org.savarese.vserv.tcpip;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* IPPacket wraps the raw bytes comprising an IPv4 packet and exposes
|
||||
* its content via setter and getter methods. After you alter the
|
||||
* header of an IP packet you have to recompute the checksum with
|
||||
* {@link #computeIPChecksum computeIPChecksum()}. The structure of
|
||||
* IP packets is described in
|
||||
* <a href="http://www.ietf.org/rfc/rfc0760.txt?number=760">RFC 760</a>.
|
||||
*
|
||||
* @author <a href="http://www.savarese.org/">Daniel F. Savarese</a>
|
||||
*/
|
||||
|
||||
public class IPPacket {
|
||||
|
||||
/** Offset into byte array of the type of service header value. */
|
||||
public static final int OFFSET_TYPE_OF_SERVICE = 1;
|
||||
|
||||
/** Offset into byte array of total packet length header value. */
|
||||
public static final int OFFSET_TOTAL_LENGTH = 2;
|
||||
|
||||
/** Offset into byte array of the identification header value. */
|
||||
public static final int OFFSET_IDENTIFICATION = 4;
|
||||
|
||||
/** Offset into byte array of the flags header value. */
|
||||
public static final int OFFSET_FLAGS = 6;
|
||||
|
||||
/** Offset into byte array of source address header value. */
|
||||
public static final int OFFSET_SOURCE_ADDRESS = 12;
|
||||
|
||||
/** Number of bytes in source address. */
|
||||
public static final int LENGTH_SOURCE_ADDRESS = 4;
|
||||
|
||||
/** Offset into byte array of destination address header value. */
|
||||
public static final int OFFSET_DESTINATION_ADDRESS = 16;
|
||||
|
||||
/** Number of bytes in destination address. */
|
||||
public static final int LENGTH_DESTINATION_ADDRESS = 4;
|
||||
|
||||
/** Offset into byte array of time to live header value. */
|
||||
public static final int OFFSET_TTL = 8;
|
||||
|
||||
/** Offset into byte array of protocol number header value. */
|
||||
public static final int OFFSET_PROTOCOL = 9;
|
||||
|
||||
/** Offset into byte array of header checksum header value. */
|
||||
public static final int OFFSET_IP_CHECKSUM = 10;
|
||||
|
||||
/** Protocol constant for IPv4. */
|
||||
public static final int PROTOCOL_IP = 0;
|
||||
|
||||
/** Protocol constant for ICMP. */
|
||||
public static final int PROTOCOL_ICMP = 1;
|
||||
|
||||
/** Protocol constant for TCP. */
|
||||
public static final int PROTOCOL_TCP = 6;
|
||||
|
||||
/** Protocol constant for UDP. */
|
||||
public static final int PROTOCOL_UDP = 17;
|
||||
|
||||
/** Raw packet data. */
|
||||
protected byte[] _data_;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new IPPacket of a given size.
|
||||
*
|
||||
* @param size The number of bytes in the packet.
|
||||
*/
|
||||
public IPPacket(int size) {
|
||||
setData(new byte[size]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The size of the packet.
|
||||
*/
|
||||
public int size() {
|
||||
return _data_.length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the raw packet byte array. Although this method would
|
||||
* appear to violate object-oriented principles, it is necessary to
|
||||
* implement efficient packet processing. You don't necessarily
|
||||
* want to allocate a new IPPacket and data buffer every time a
|
||||
* packet arrives and you need to be able to wrap packets from
|
||||
* APIs that supply them as byte arrays.
|
||||
*
|
||||
* @param data The raw packet byte array to wrap.
|
||||
*/
|
||||
public void setData(byte[] data) {
|
||||
_data_ = data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the raw packet data into a byte array. If the array
|
||||
* is too small to hold the data, the data is truncated.
|
||||
*
|
||||
* @param data The raw packet byte array to wrap.
|
||||
*/
|
||||
public void getData(byte[] data) {
|
||||
System.arraycopy(_data_, 0, data, 0, data.length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the contents of an IPPacket to the calling instance. If
|
||||
* the two packets are of different lengths, a new byte array is
|
||||
* allocated equal to the length of the packet parameter.
|
||||
*
|
||||
* @param packet The packet to copy from.
|
||||
*/
|
||||
public final void copy(IPPacket packet) {
|
||||
if(_data_.length != packet.size())
|
||||
setData(new byte[packet.size()]);
|
||||
System.arraycopy(packet._data_, 0, _data_, 0, _data_.length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the IP version header value.
|
||||
*
|
||||
* @param version A 4-bit unsigned integer.
|
||||
*/
|
||||
public final void setIPVersion(int version) {
|
||||
_data_[0] &= 0x0f;
|
||||
_data_[0] |= ((version << 4) & 0xf0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the IP version header value.
|
||||
*
|
||||
* @return The IP version header value.
|
||||
*/
|
||||
public final int getIPVersion() {
|
||||
return ((_data_[0] & 0xf0) >> 4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the IP header length field. At most, this can be a
|
||||
* four-bit value. The high order bits beyond the fourth bit
|
||||
* will be ignored.
|
||||
*
|
||||
* @param length The length of the IP header in 32-bit words.
|
||||
*/
|
||||
public void setIPHeaderLength(int length) {
|
||||
// Clear low order bits and then set
|
||||
_data_[0] &= 0xf0;
|
||||
_data_[0] |= (length & 0x0f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The length of the IP header in 32-bit words.
|
||||
*/
|
||||
public final int getIPHeaderLength() {
|
||||
return (_data_[0] & 0x0f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The length of the IP header in bytes.
|
||||
*/
|
||||
public final int getIPHeaderByteLength() {
|
||||
return getIPHeaderLength() << 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the IP type of service header value. You have to set the individual
|
||||
* service bits yourself. Convenience methods for setting the service
|
||||
* bit fields directly may be added in a future version.
|
||||
*
|
||||
* @param service An 8-bit unsigned integer.
|
||||
*/
|
||||
public final void setTypeOfService(int service) {
|
||||
_data_[OFFSET_TYPE_OF_SERVICE] = (byte)(service & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the IP type of service header value.
|
||||
*
|
||||
* @return The IP type of service header value.
|
||||
*/
|
||||
public final int getTypeOfService() {
|
||||
return (_data_[OFFSET_TYPE_OF_SERVICE] & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the IP packet total length header value.
|
||||
*
|
||||
* @param length The total IP packet length in bytes.
|
||||
*/
|
||||
public final void setIPPacketLength(int length) {
|
||||
_data_[OFFSET_TOTAL_LENGTH] = (byte)((length >> 8) & 0xff);
|
||||
_data_[OFFSET_TOTAL_LENGTH + 1] = (byte)(length & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The IP packet total length header value.
|
||||
*/
|
||||
public final int getIPPacketLength() {
|
||||
return (((_data_[OFFSET_TOTAL_LENGTH] & 0xff) << 8) |
|
||||
(_data_[OFFSET_TOTAL_LENGTH + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the IP identification header value.
|
||||
*
|
||||
* @param id A 16-bit unsigned integer.
|
||||
*/
|
||||
public void setIdentification(int id) {
|
||||
_data_[OFFSET_IDENTIFICATION] = (byte)((id >> 8) & 0xff);
|
||||
_data_[OFFSET_IDENTIFICATION + 1] = (byte)(id & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the IP identification header value.
|
||||
*
|
||||
* @return The IP identification header value.
|
||||
*/
|
||||
public final int getIdentification() {
|
||||
return (((_data_[OFFSET_IDENTIFICATION] & 0xff) << 8) |
|
||||
(_data_[OFFSET_IDENTIFICATION + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the IP flags header value. You have to set the individual
|
||||
* flag bits yourself. Convenience methods for setting the flag
|
||||
* bit fields directly may be added in a future version.
|
||||
*
|
||||
* @param flags A 3-bit unsigned integer.
|
||||
*/
|
||||
public final void setIPFlags(int flags) {
|
||||
_data_[OFFSET_FLAGS] &= 0x1f;
|
||||
_data_[OFFSET_FLAGS] |= ((flags << 5) & 0xe0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the IP flags header value.
|
||||
*
|
||||
* @return The IP flags header value.
|
||||
*/
|
||||
public final int getIPFlags() {
|
||||
return ((_data_[OFFSET_FLAGS] & 0xe0) >> 5);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the fragment offset header value. The offset specifies a
|
||||
* number of octets (i.e., bytes).
|
||||
*
|
||||
* @param offset A 13-bit unsigned integer.
|
||||
*/
|
||||
public void setFragmentOffset(int offset) {
|
||||
_data_[OFFSET_FLAGS] &= 0xe0;
|
||||
_data_[OFFSET_FLAGS] |= ((offset >> 8) & 0x1f);
|
||||
_data_[OFFSET_FLAGS + 1] = (byte)(offset & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the fragment offset header value.
|
||||
*
|
||||
* @return The fragment offset header value.
|
||||
*/
|
||||
public final int getFragmentOffset() {
|
||||
return (((_data_[OFFSET_FLAGS] & 0x1f) << 8) |
|
||||
(_data_[OFFSET_FLAGS + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the protocol number.
|
||||
*
|
||||
* @param protocol The protocol number.
|
||||
*/
|
||||
public final void setProtocol(int protocol) {
|
||||
_data_[OFFSET_PROTOCOL] = (byte)protocol;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The protocol number.
|
||||
*/
|
||||
public final int getProtocol() {
|
||||
return _data_[OFFSET_PROTOCOL];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the time to live value in seconds.
|
||||
*
|
||||
* @param ttl The time to live value in seconds.
|
||||
*/
|
||||
public final void setTTL(int ttl) {
|
||||
_data_[OFFSET_TTL] = (byte)ttl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The time to live value in seconds.
|
||||
*/
|
||||
public final int getTTL() {
|
||||
return _data_[OFFSET_TTL];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates checksums assuming the checksum is a 16-bit header field.
|
||||
* This method is generalized to work for IP, ICMP, UDP, and TCP packets
|
||||
* given the proper parameters.
|
||||
*/
|
||||
protected int _computeChecksum_(int startOffset,
|
||||
int checksumOffset,
|
||||
int length,
|
||||
int virtualHeaderTotal,
|
||||
boolean update)
|
||||
{
|
||||
int total = 0;
|
||||
int i = startOffset;
|
||||
int imax = checksumOffset;
|
||||
|
||||
while(i < imax)
|
||||
total+=(((_data_[i++] & 0xff) << 8) | (_data_[i++] & 0xff));
|
||||
|
||||
// Skip existing checksum.
|
||||
i = checksumOffset + 2;
|
||||
|
||||
imax = length - (length % 2);
|
||||
|
||||
while(i < imax)
|
||||
total+=(((_data_[i++] & 0xff) << 8) | (_data_[i++] & 0xff));
|
||||
|
||||
if(i < length)
|
||||
total+=((_data_[i] & 0xff) << 8);
|
||||
|
||||
total+=virtualHeaderTotal;
|
||||
|
||||
// Fold to 16 bits
|
||||
while((total & 0xffff0000) != 0)
|
||||
total = (total & 0xffff) + (total >>> 16);
|
||||
|
||||
total = (~total & 0xffff);
|
||||
|
||||
if(update) {
|
||||
_data_[checksumOffset] = (byte)(total >> 8);
|
||||
_data_[checksumOffset + 1] = (byte)(total & 0xff);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the IP checksum, optionally updating the IP checksum header.
|
||||
*
|
||||
* @param update Specifies whether or not to update the IP checksum
|
||||
* header after computing the checksum. A value of true indicates
|
||||
* the header should be updated, a value of false indicates it
|
||||
* should not be updated.
|
||||
* @return The computed IP checksum.
|
||||
*/
|
||||
public final int computeIPChecksum(boolean update) {
|
||||
return _computeChecksum_(0, OFFSET_IP_CHECKSUM, getIPHeaderByteLength(),
|
||||
0, update);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>computeIPChecksum(true);</code>
|
||||
*
|
||||
* @return The computed IP checksum value.
|
||||
*/
|
||||
public final int computeIPChecksum() {
|
||||
return computeIPChecksum(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The IP checksum header value.
|
||||
*/
|
||||
public final int getIPChecksum() {
|
||||
return (((_data_[OFFSET_IP_CHECKSUM] & 0xff) << 8) |
|
||||
(_data_[OFFSET_IP_CHECKSUM + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the source IP address into a byte array. The array
|
||||
* should be {@link #LENGTH_SOURCE_ADDRESS} bytes long.
|
||||
*
|
||||
* @param address The array in which to store the address.
|
||||
*/
|
||||
public final void getSource(byte[] address) {
|
||||
System.arraycopy(_data_, OFFSET_SOURCE_ADDRESS, address,
|
||||
0, (address.length < LENGTH_SOURCE_ADDRESS ?
|
||||
address.length : LENGTH_SOURCE_ADDRESS));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the destionation IP address into a byte array. The array
|
||||
* should be {@link #LENGTH_DESTINATION_ADDRESS} bytes long.
|
||||
*
|
||||
* @param address The array in which to store the address.
|
||||
*/
|
||||
public final void getDestination(byte[] address) {
|
||||
System.arraycopy(_data_, OFFSET_DESTINATION_ADDRESS, address,
|
||||
0, (address.length < LENGTH_DESTINATION_ADDRESS ?
|
||||
address.length : LENGTH_DESTINATION_ADDRESS));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the source IP address as a string into a StringBuffer.
|
||||
*
|
||||
* @param buffer The StringBuffer in which to store the address.
|
||||
*/
|
||||
public final void getSource(StringBuffer buffer) {
|
||||
OctetConverter.octetsToString(buffer, _data_, OFFSET_SOURCE_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the destination IP address as a string into a StringBuffer.
|
||||
*
|
||||
* @param buffer The StringBuffer in which to store the address.
|
||||
*/
|
||||
public final void getDestination(StringBuffer buffer) {
|
||||
OctetConverter.octetsToString(buffer, _data_, OFFSET_DESTINATION_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the source IP address using a word representation.
|
||||
*
|
||||
* @param src The source IP address as a 32-bit word.
|
||||
*/
|
||||
public final void setSourceAsWord(int src) {
|
||||
OctetConverter.intToOctets(src, _data_, OFFSET_SOURCE_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the destination IP address using a word representation.
|
||||
*
|
||||
* @param dest The source IP address as a 32-bit word.
|
||||
*/
|
||||
public final void setDestinationAsWord(int dest) {
|
||||
OctetConverter.intToOctets(dest, _data_, OFFSET_DESTINATION_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The source IP address as a 32-bit word.
|
||||
*/
|
||||
public final int getSourceAsWord() {
|
||||
return OctetConverter.octetsToInt(_data_, OFFSET_SOURCE_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The destination IP address as a 32-bit word.
|
||||
*/
|
||||
public final int getDestinationAsWord() {
|
||||
return OctetConverter.octetsToInt(_data_, OFFSET_DESTINATION_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The source IP address as a java.net.InetAddress instance.
|
||||
*/
|
||||
public final InetAddress getSourceAsInetAddress()
|
||||
throws UnknownHostException
|
||||
{
|
||||
byte[] octets = new byte[4];
|
||||
getSource(octets);
|
||||
return InetAddress.getByAddress(octets);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return The destination IP address as a java.net.InetAddress instance.
|
||||
*/
|
||||
public final InetAddress getDestinationAsInetAddress()
|
||||
throws UnknownHostException
|
||||
{
|
||||
byte[] octets = new byte[4];
|
||||
getDestination(octets);
|
||||
return InetAddress.getByAddress(octets);
|
||||
}
|
||||
}
|
||||
183
ipscan/ext/vserv-tcpip/src/java/org/savarese/vserv/tcpip/OctetConverter.java
Executable file
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* $Id: OctetConverter.java 5067 2005-03-24 06:10:10Z dfs $
|
||||
*
|
||||
* Copyright 2004-2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
|
||||
package org.savarese.vserv.tcpip;
|
||||
|
||||
/**
|
||||
* OctetConverter is a utility singleton class for converting IP
|
||||
* octets to and from other representations.
|
||||
*
|
||||
* @author <a href="http://www.savarese.org/">Daniel F. Savarese</a>
|
||||
*/
|
||||
|
||||
public final class OctetConverter {
|
||||
|
||||
private OctetConverter() { }
|
||||
|
||||
/**
|
||||
* Converts a set of IPv4 octets to a 32-bit word.
|
||||
*
|
||||
* @param octets A byte array containing the IPv4 octets.
|
||||
* @param offset The offset into the array where the octets start.
|
||||
* @return The 32-bit word representation of the IPv4 address.
|
||||
*/
|
||||
public static final int octetsToInt(byte[] octets, int offset) {
|
||||
return (((octets[offset] & 0xff) << 24) |
|
||||
((octets[offset + 1] & 0xff) << 16) |
|
||||
((octets[offset + 2] & 0xff) << 8) |
|
||||
(octets[offset + 3] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>octetsToInt(octets, 0);</code>
|
||||
*/
|
||||
public static final int octetsToInt(byte[] octets) {
|
||||
return octetsToInt(octets, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a set of octets to a 64-bit word.
|
||||
*
|
||||
* @param octets A byte array containing the octets.
|
||||
* @param offset The offset into the array where the octets start.
|
||||
* @return The 64-bit word representation of the octets.
|
||||
*/
|
||||
public static final long octetsToLong(byte[] octets, int offset) {
|
||||
return (((octets[offset] & 0xffffL) << 56) |
|
||||
((octets[offset + 1] & 0xffL) << 48) |
|
||||
((octets[offset + 2] & 0xffL) << 40) |
|
||||
((octets[offset + 3] & 0xffL) << 32) |
|
||||
((octets[offset + 4] & 0xffL) << 24) |
|
||||
((octets[offset + 5] & 0xffL) << 16) |
|
||||
((octets[offset + 6] & 0xffL) << 8) |
|
||||
(octets[offset + 7] & 0xffL));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>octetsToLong(octets, 0);</code>
|
||||
*/
|
||||
public static final long octetsToLong(byte[] octets) {
|
||||
return octetsToLong(octets, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a set of IPv4 octets to a string representation.
|
||||
*
|
||||
* @param buffer The StringBuffer to which to append the string.
|
||||
* @param octets A byte array containing the IPv4 octets.
|
||||
* @param offset The offset into the array where the octets start.
|
||||
*/
|
||||
public static final void octetsToString(StringBuffer buffer, byte[] octets,
|
||||
int offset)
|
||||
{
|
||||
buffer.append(octets[offset++] & 0xff);
|
||||
buffer.append(".");
|
||||
buffer.append(octets[offset++] & 0xff);
|
||||
buffer.append(".");
|
||||
buffer.append(octets[offset++] & 0xff);
|
||||
buffer.append(".");
|
||||
buffer.append(octets[offset++] & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>octetsToString(buffer, octets, 0);</code>
|
||||
*/
|
||||
public static final void octetsToString(StringBuffer buffer, byte[] octets) {
|
||||
octetsToString(buffer, octets, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a 32-bit word representation of an IPv4 address to a
|
||||
* string representation.
|
||||
*
|
||||
* @param buffer The StringBuffer to which to append the string.
|
||||
* @param address The 32-bit word representation of the address.
|
||||
*/
|
||||
public static final void intToString(StringBuffer buffer, int address) {
|
||||
buffer.append(0xff & (address >>> 24));
|
||||
buffer.append(".");
|
||||
buffer.append(0xff & (address >>> 16));
|
||||
buffer.append(".");
|
||||
buffer.append(0xff & (address >>> 8));
|
||||
buffer.append(".");
|
||||
buffer.append(0xff & address);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a 32-bit word representation of an IPv4 address to a
|
||||
* byte array of octets.
|
||||
*
|
||||
* @param address The 32-bit word representation of the IPv4 address.
|
||||
* @param octets The byte array in which to store the IPv4 octets.
|
||||
* @param offset The offset into the array where the octets start.
|
||||
*/
|
||||
public static final void intToOctets(int address, byte[] octets,
|
||||
int offset)
|
||||
{
|
||||
octets[offset] = (byte)(0xff & (address >>> 24));
|
||||
octets[offset + 1] = (byte)(0xff & (address >>> 16));
|
||||
octets[offset + 2] = (byte)(0xff & (address >>> 8));
|
||||
octets[offset + 3] = (byte)(0xff & address);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>intToOctets(address, octets, 0);</code>
|
||||
*/
|
||||
public static final void intToOctets(int address, byte[] octets) {
|
||||
intToOctets(address, octets, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a 64-bit word to a byte array of octets.
|
||||
*
|
||||
* @param address The 64-bit word.
|
||||
* @param octets The byte array in which to store octets.
|
||||
* @param offset The offset into the array where the octets start.
|
||||
*/
|
||||
public static final void longToOctets(long address, byte[] octets,
|
||||
int offset)
|
||||
{
|
||||
octets[offset] = (byte)(0xffL & (address >>> 56));
|
||||
octets[offset + 1] = (byte)(0xffL & (address >>> 48));
|
||||
octets[offset + 2] = (byte)(0xffL & (address >>> 40));
|
||||
octets[offset + 3] = (byte)(0xffL & (address >>> 32));
|
||||
octets[offset + 4] = (byte)(0xffL & (address >>> 24));
|
||||
octets[offset + 5] = (byte)(0xffL & (address >>> 16));
|
||||
octets[offset + 6] = (byte)(0xffL & (address >>> 8));
|
||||
octets[offset + 7] = (byte)(0xffL & address);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>longToOctets(address, octets, 0);</code>
|
||||
*/
|
||||
public static final void longToOctets(long address, byte[] octets) {
|
||||
longToOctets(address, octets, 0);
|
||||
}
|
||||
|
||||
}
|
||||
492
ipscan/ext/vserv-tcpip/src/java/org/savarese/vserv/tcpip/TCPPacket.java
Executable file
@ -0,0 +1,492 @@
|
||||
/*
|
||||
* $Id: TCPPacket.java 6023 2005-12-10 20:42:15Z dfs $
|
||||
*
|
||||
* Copyright 2004-2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
|
||||
package org.savarese.vserv.tcpip;
|
||||
|
||||
/**
|
||||
* TCPPacket extends {@link IPPacket} to handle TCP packets. The TCP
|
||||
* packet structure is described in
|
||||
* <a href="http://www.ietf.org/rfc/rfc0761.txt?number=761">RFC 761</a>.
|
||||
*
|
||||
* @author <a href="http://www.savarese.org/">Daniel F. Savarese</a>
|
||||
*/
|
||||
|
||||
public class TCPPacket extends IPPacket {
|
||||
|
||||
/** Offset into the TCP packet of the source port header value. */
|
||||
public static final int OFFSET_SOURCE_PORT = 0;
|
||||
|
||||
/** Offset into the TCP packet of the destination port header value. */
|
||||
public static final int OFFSET_DESTINATION_PORT = 2;
|
||||
|
||||
/** Offset into the TCP packet of the sequence number header value. */
|
||||
public static final int OFFSET_SEQUENCE = 4;
|
||||
|
||||
/** Offset into the TCP packet of the acknowledgement number header value. */
|
||||
public static final int OFFSET_ACK = 8;
|
||||
|
||||
/** Offset into the TCP packet of the TCP header length. */
|
||||
public static final int OFFSET_HEADER_LENGTH = 12;
|
||||
|
||||
/** Offset into the TCP packet of the control header. */
|
||||
public static final int OFFSET_CONTROL = 13;
|
||||
|
||||
/** Offset into the TCP packet of the window size. */
|
||||
public static final int OFFSET_WINDOW_SIZE = 14;
|
||||
|
||||
/** Offset into the TCP packet of the TCP checksum. */
|
||||
public static final int OFFSET_TCP_CHECKSUM = 16;
|
||||
|
||||
/** Offset into the TCP packet of the URG pointer. */
|
||||
public static final int OFFSET_URG_POINTER = 18;
|
||||
|
||||
/** A mask for extracting the FIN bit from the control header. */
|
||||
public static final int MASK_FIN = 0x01;
|
||||
|
||||
/** A mask for extracting the SYN bit from the control header. */
|
||||
public static final int MASK_SYN = 0x02;
|
||||
|
||||
/** A mask for extracting the reset bit from the control header. */
|
||||
public static final int MASK_RST = 0x04;
|
||||
|
||||
/** A mask for extracting the push bit from the control header. */
|
||||
public static final int MASK_PSH = 0x08;
|
||||
|
||||
/** A mask for extracting the ACK bit from the control header. */
|
||||
public static final int MASK_ACK = 0x10;
|
||||
|
||||
/** A mask for extracting the urgent bit from the control header. */
|
||||
public static final int MASK_URG = 0x20;
|
||||
|
||||
/** A byte value for TCP options indicating end of option list. */
|
||||
public static final byte KIND_EOL = 0;
|
||||
|
||||
/** A byte value for TCP options indicating no operation. */
|
||||
public static final byte KIND_NOP = 1;
|
||||
|
||||
/**
|
||||
* A byte value for TCP options identifying a selective
|
||||
* acknowledgement option.
|
||||
*/
|
||||
public static final byte KIND_SACK = 4;
|
||||
|
||||
/** The byte offset into the IP packet where the TCP packet begins. */
|
||||
private int __offset;
|
||||
|
||||
/**
|
||||
* Creates a new TCP packet of a given size.
|
||||
*
|
||||
* @param size The number of bytes in the packet.
|
||||
*/
|
||||
public TCPPacket(int size) {
|
||||
super(size);
|
||||
__offset = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new TCP packet that is a copy of a given packet.
|
||||
*
|
||||
* @param packet The packet to replicate.
|
||||
*/
|
||||
public TCPPacket(TCPPacket packet) {
|
||||
super(packet.size());
|
||||
copy(packet);
|
||||
__offset = packet.__offset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears all selective acknowledgement options. This is a
|
||||
* temporary kluge and will be removed from the final API. Do not
|
||||
* use it. The final API will have proper methods for adjusting
|
||||
* selective acknowledgement options.
|
||||
*/
|
||||
public void clearSACK() {
|
||||
int headerLength = getTCPHeaderByteLength();
|
||||
int offset = OFFSET_URG_POINTER + 2;
|
||||
|
||||
if(headerLength > offset) {
|
||||
offset+=__offset;
|
||||
headerLength+=__offset;
|
||||
|
||||
loop:
|
||||
do {
|
||||
byte kind = _data_[offset];
|
||||
|
||||
switch(kind) {
|
||||
case KIND_NOP:
|
||||
++offset;
|
||||
break;
|
||||
case KIND_EOL:
|
||||
break loop;
|
||||
case KIND_SACK:
|
||||
_data_[offset] = KIND_NOP;
|
||||
_data_[offset + 1] = KIND_NOP;
|
||||
break loop;
|
||||
//break;
|
||||
default:
|
||||
offset+=_data_[offset + 1];
|
||||
/*
|
||||
int length = _data_[offset + 1];
|
||||
while(length-- > 0)
|
||||
_data_[offset++] = KIND_NOP;
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
} while(offset < headerLength);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the contents of a TCPPacket. If the current data array is
|
||||
* of insufficient length to store the contents, a new array is
|
||||
* allocated.
|
||||
*
|
||||
* @param packet The TCPPacket to copy.
|
||||
*/
|
||||
public final void copyData(TCPPacket packet) {
|
||||
if(_data_.length < packet._data_.length) {
|
||||
byte[] data = new byte[packet._data_.length];
|
||||
System.arraycopy(_data_, 0, data, 0, getCombinedHeaderByteLength());
|
||||
_data_ = data;
|
||||
}
|
||||
int length = packet.getTCPDataByteLength();
|
||||
System.arraycopy(packet._data_, packet.getCombinedHeaderByteLength(),
|
||||
_data_, getCombinedHeaderByteLength(), length);
|
||||
setTCPDataByteLength(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mask The bit mask to check.
|
||||
* @return True only if all of the bits in the mask are set.
|
||||
*/
|
||||
public boolean isSet(int mask) {
|
||||
return ((_data_[__offset + OFFSET_CONTROL] & mask) == mask);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mask The bit mask to check.
|
||||
* @return True if any of the bits in the mask are set.
|
||||
*/
|
||||
public boolean isSetAny(int mask) {
|
||||
return ((_data_[__offset + OFFSET_CONTROL] & mask) != 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mask The bit mask to check.
|
||||
* @return True only if all of the bits in the mask are set
|
||||
* and ONLY the bits in the mask are set.
|
||||
*/
|
||||
public boolean isSetOnly(int mask) {
|
||||
int flags = _data_[__offset + OFFSET_CONTROL] & 0xff;
|
||||
return ((flags & mask) == flags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the specified control bits without altering any other bits
|
||||
* in the control header.
|
||||
*
|
||||
* @param mask The bits to set.
|
||||
*/
|
||||
public void addControlFlags(int mask) {
|
||||
int flags = _data_[__offset + OFFSET_CONTROL] & 0xff;
|
||||
flags |= mask;
|
||||
_data_[__offset + OFFSET_CONTROL] = (byte)(flags & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unsets the specified control bits.
|
||||
*
|
||||
* @param mask The bits to unset.
|
||||
*/
|
||||
public void removeControlFlags(int mask) {
|
||||
int flags = _data_[__offset + OFFSET_CONTROL] & 0xff;
|
||||
flags |= mask;
|
||||
flags ^= mask;
|
||||
_data_[__offset + OFFSET_CONTROL] = (byte)(flags & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the control header to the sepecified value.
|
||||
*
|
||||
* @param mask The new control header bit mask.
|
||||
*/
|
||||
public void setControlFlags(int mask) {
|
||||
_data_[__offset + OFFSET_CONTROL] = (byte)(mask & 0xff);
|
||||
}
|
||||
|
||||
|
||||
public void setData(byte[] data) {
|
||||
super.setData(data);
|
||||
__offset = getIPHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the source port.
|
||||
*
|
||||
* @param port The new source port.
|
||||
*/
|
||||
public final void setSourcePort(int port) {
|
||||
_data_[__offset + OFFSET_SOURCE_PORT] = (byte)((port >> 8) & 0xff);
|
||||
_data_[__offset + OFFSET_SOURCE_PORT + 1] = (byte)(port & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the destination port.
|
||||
*
|
||||
* @param port The new destination port.
|
||||
*/
|
||||
public final void setDestinationPort(int port) {
|
||||
_data_[__offset + OFFSET_DESTINATION_PORT] = (byte)((port >> 8) & 0xff);
|
||||
_data_[__offset + OFFSET_DESTINATION_PORT + 1] = (byte)(port & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The source port.
|
||||
*/
|
||||
public final int getSourcePort() {
|
||||
return (((_data_[__offset + OFFSET_SOURCE_PORT] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_SOURCE_PORT + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The destination port.
|
||||
*/
|
||||
public final int getDestinationPort() {
|
||||
return (((_data_[__offset + OFFSET_DESTINATION_PORT] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_DESTINATION_PORT + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the sequence number.
|
||||
*
|
||||
* @param seq The new sequence number.
|
||||
*/
|
||||
public final void setSequenceNumber(long seq) {
|
||||
OctetConverter.intToOctets((int)(seq & 0xffffffff), _data_,
|
||||
__offset + OFFSET_SEQUENCE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The sequence number.
|
||||
*/
|
||||
public final long getSequenceNumber() {
|
||||
return (((_data_[__offset + OFFSET_SEQUENCE] & 0xffL) << 24) |
|
||||
((_data_[__offset + OFFSET_SEQUENCE + 1] & 0xffL) << 16) |
|
||||
((_data_[__offset + OFFSET_SEQUENCE + 2] & 0xffL) << 8) |
|
||||
(_data_[__offset + OFFSET_SEQUENCE + 3] & 0xffL));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the acknowledgement number.
|
||||
*
|
||||
* @param seq The new acknowledgement number.
|
||||
*/
|
||||
public final void setAckNumber(long seq) {
|
||||
OctetConverter.intToOctets((int)(seq & 0xffffffff), _data_,
|
||||
__offset + OFFSET_ACK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The acknowledgement number.
|
||||
*/
|
||||
public final long getAckNumber() {
|
||||
return (((_data_[__offset + OFFSET_ACK] & 0xffL) << 24) |
|
||||
((_data_[__offset + OFFSET_ACK + 1] & 0xffL) << 16) |
|
||||
((_data_[__offset + OFFSET_ACK + 2] & 0xffL) << 8) |
|
||||
(_data_[__offset + OFFSET_ACK + 3] & 0xffL));
|
||||
}
|
||||
|
||||
|
||||
public void setIPHeaderLength(int length) {
|
||||
super.setIPHeaderLength(length);
|
||||
__offset = getIPHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets te TCP header length (i.e., the data offset field) in 32-bit words.
|
||||
*
|
||||
* @param length The TCP header length in 32-bit words.
|
||||
*/
|
||||
public final void setTCPHeaderLength(int length) {
|
||||
_data_[__offset + OFFSET_HEADER_LENGTH] &= 0x0f;
|
||||
_data_[__offset + OFFSET_HEADER_LENGTH] |= ((length << 4) & 0xf0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The TCP header length in 32-bit words.
|
||||
*/
|
||||
public final int getTCPHeaderLength() {
|
||||
return (_data_[__offset + OFFSET_HEADER_LENGTH] & 0xf0) >> 4;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The TCP header length in bytes.
|
||||
*/
|
||||
public final int getTCPHeaderByteLength() {
|
||||
return getTCPHeaderLength() << 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the TCP window size.
|
||||
*
|
||||
* @param window The TCP window size.
|
||||
*/
|
||||
public final void setWindowSize(int window) {
|
||||
_data_[__offset + OFFSET_WINDOW_SIZE] = (byte)((window >> 8) & 0xff);
|
||||
_data_[__offset + OFFSET_WINDOW_SIZE + 1] = (byte)(window & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The TCP window size.
|
||||
*/
|
||||
public final int getWindowSize() {
|
||||
return (((_data_[__offset + OFFSET_WINDOW_SIZE] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_WINDOW_SIZE + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the urgent pointer.
|
||||
*
|
||||
* @param pointer The urgent pointer value.
|
||||
*/
|
||||
public final void setUrgentPointer(int pointer) {
|
||||
_data_[__offset + OFFSET_URG_POINTER] = (byte)((pointer >> 8) & 0xff);
|
||||
_data_[__offset + OFFSET_URG_POINTER + 1] = (byte)(pointer & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The urgent pointer value.
|
||||
*/
|
||||
public final int getUrgentPointer() {
|
||||
return (((_data_[__offset + OFFSET_URG_POINTER] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_URG_POINTER + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The TCP checksum.
|
||||
*/
|
||||
public final int getTCPChecksum() {
|
||||
return (((_data_[__offset + OFFSET_TCP_CHECKSUM] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_TCP_CHECKSUM + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The TCP packet length in bytes. This is the size of the
|
||||
* IP packet minus the size of the IP header.
|
||||
*/
|
||||
public final int getTCPPacketByteLength() {
|
||||
return getIPPacketLength() - __offset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The IP header length plus the TCP header length in bytes.
|
||||
*/
|
||||
public final int getCombinedHeaderByteLength() {
|
||||
return __offset + getTCPHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the length of the TCP data payload.
|
||||
*
|
||||
* @param length The length of the TCP data payload in bytes.
|
||||
*/
|
||||
public final void setTCPDataByteLength(int length) {
|
||||
if(length < 0)
|
||||
length = 0;
|
||||
|
||||
setIPPacketLength(getCombinedHeaderByteLength() + length);
|
||||
}
|
||||
|
||||
|
||||
public final int getTCPDataByteLength() {
|
||||
return getIPPacketLength() - getCombinedHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
private final int __getVirtualHeaderTotal() {
|
||||
int s1 =
|
||||
((_data_[OFFSET_SOURCE_ADDRESS] & 0xff) << 8) |
|
||||
(_data_[OFFSET_SOURCE_ADDRESS + 1] & 0xff);
|
||||
int s2 =
|
||||
((_data_[OFFSET_SOURCE_ADDRESS + 2] & 0xff) << 8) |
|
||||
(_data_[OFFSET_SOURCE_ADDRESS + 3] & 0xff);
|
||||
int d1 =
|
||||
((_data_[OFFSET_DESTINATION_ADDRESS] & 0xff) << 8) |
|
||||
(_data_[OFFSET_DESTINATION_ADDRESS + 1] & 0xff);
|
||||
int d2 =
|
||||
((_data_[OFFSET_DESTINATION_ADDRESS + 2] & 0xff) << 8) |
|
||||
(_data_[OFFSET_DESTINATION_ADDRESS + 3] & 0xff);
|
||||
return s1 + s2 + d1 + d2 + getProtocol() + getTCPPacketByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the TCP checksum, optionally updating the TCP checksum header.
|
||||
*
|
||||
* @param update Specifies whether or not to update the TCP checksum
|
||||
* header after computing the checksum. A value of true indicates
|
||||
* the header should be updated, a value of false indicates it
|
||||
* should not be updated.
|
||||
* @return The computed TCP checksum.
|
||||
*/
|
||||
public final int computeTCPChecksum(boolean update) {
|
||||
return _computeChecksum_(__offset, __offset + OFFSET_TCP_CHECKSUM,
|
||||
getIPPacketLength(), __getVirtualHeaderTotal(),
|
||||
update);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>computeTCPChecksum(true);</code>
|
||||
*
|
||||
* @return The computed TCP checksum value.
|
||||
*/
|
||||
public final int computeTCPChecksum() {
|
||||
return computeTCPChecksum(true);
|
||||
}
|
||||
}
|
||||
252
ipscan/ext/vserv-tcpip/src/java/org/savarese/vserv/tcpip/UDPPacket.java
Executable file
@ -0,0 +1,252 @@
|
||||
/*
|
||||
* $Id: UDPPacket.java 5347 2005-05-25 22:45:54Z dfs $
|
||||
*
|
||||
* Copyright 2005 Daniel F. Savarese
|
||||
* Contact Information: http://www.savarese.org/contact.html
|
||||
*
|
||||
* 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.savarese.org/software/ApacheLicense-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.
|
||||
*/
|
||||
|
||||
package org.savarese.vserv.tcpip;
|
||||
|
||||
/**
|
||||
* UDPPacket extends {@link IPPacket} to handle UDP packets. The UDP
|
||||
* packet structure is described in
|
||||
* <a href="http://www.ietf.org/rfc/rfc0768.txt?number=768">RFC 768</a>.
|
||||
*
|
||||
* @author <a href="http://www.savarese.org/">Daniel F. Savarese</a>
|
||||
*/
|
||||
|
||||
public class UDPPacket extends IPPacket {
|
||||
|
||||
/** Offset into the UDP packet of the source port header value. */
|
||||
public static final int OFFSET_SOURCE_PORT = 0;
|
||||
|
||||
/** Offset into the UDP packet of the destination port header value. */
|
||||
public static final int OFFSET_DESTINATION_PORT = 2;
|
||||
|
||||
/** Offset into the UDP packet of UDP total packet length header value. */
|
||||
public static final int OFFSET_UDP_TOTAL_LENGTH = 4;
|
||||
|
||||
/** Offset into the UDP packet of the UDP checksum. */
|
||||
public static final int OFFSET_UDP_CHECKSUM = 6;
|
||||
|
||||
/** Length of the UDP packet header in bytes. */
|
||||
public static final int LENGTH_UDP_HEADER = 8;
|
||||
|
||||
/** The byte offset into the IP packet where the UDP packet begins. */
|
||||
private int __offset;
|
||||
|
||||
/**
|
||||
* Creates a new UDP packet of a given size.
|
||||
*
|
||||
* @param size The number of bytes in the packet.
|
||||
*/
|
||||
public UDPPacket(int size) {
|
||||
super(size);
|
||||
__offset = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new UDP packet that is a copy of a given packet.
|
||||
*
|
||||
* @param packet The packet to replicate.
|
||||
*/
|
||||
public UDPPacket(UDPPacket packet) {
|
||||
super(packet.size());
|
||||
copy(packet);
|
||||
__offset = packet.__offset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the contents of a UDPPacket. If the current data array is
|
||||
* of insufficient length to store the contents, a new array is
|
||||
* allocated.
|
||||
*
|
||||
* @param packet The UDPPacket to copy.
|
||||
*/
|
||||
public final void copyData(UDPPacket packet) {
|
||||
if(_data_.length < packet._data_.length) {
|
||||
byte[] data = new byte[packet._data_.length];
|
||||
System.arraycopy(_data_, 0, data, 0, getCombinedHeaderByteLength());
|
||||
_data_ = data;
|
||||
}
|
||||
int length = packet.getUDPDataByteLength();
|
||||
System.arraycopy(packet._data_, packet.getCombinedHeaderByteLength(),
|
||||
_data_, getCombinedHeaderByteLength(), length);
|
||||
setUDPDataByteLength(length);
|
||||
}
|
||||
|
||||
|
||||
public void setData(byte[] data) {
|
||||
super.setData(data);
|
||||
__offset = getIPHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the source port.
|
||||
*
|
||||
* @param port The new source port.
|
||||
*/
|
||||
public final void setSourcePort(int port) {
|
||||
_data_[__offset + OFFSET_SOURCE_PORT] = (byte)((port >> 8) & 0xff);
|
||||
_data_[__offset + OFFSET_SOURCE_PORT + 1] = (byte)(port & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the destination port.
|
||||
*
|
||||
* @param port The new destination port.
|
||||
*/
|
||||
public final void setDestinationPort(int port) {
|
||||
_data_[__offset + OFFSET_DESTINATION_PORT] = (byte)((port >> 8) & 0xff);
|
||||
_data_[__offset + OFFSET_DESTINATION_PORT + 1] = (byte)(port & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The source port.
|
||||
*/
|
||||
public final int getSourcePort() {
|
||||
return (((_data_[__offset + OFFSET_SOURCE_PORT] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_SOURCE_PORT + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The destination port.
|
||||
*/
|
||||
public final int getDestinationPort() {
|
||||
return (((_data_[__offset + OFFSET_DESTINATION_PORT] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_DESTINATION_PORT + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
public void setIPHeaderLength(int length) {
|
||||
super.setIPHeaderLength(length);
|
||||
__offset = getIPHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the UDP total length header field.
|
||||
*
|
||||
* @param length The length of the UDP packet in bytes.
|
||||
*/
|
||||
public void setUDPPacketLength(int length) {
|
||||
_data_[__offset + OFFSET_UDP_TOTAL_LENGTH] = (byte)((length >> 8) & 0xff);
|
||||
_data_[__offset + OFFSET_UDP_TOTAL_LENGTH + 1] = (byte)(length & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The value of the UDP total length header field.
|
||||
*/
|
||||
public final int getUDPPacketLength() {
|
||||
return (((_data_[__offset + OFFSET_UDP_TOTAL_LENGTH] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_UDP_TOTAL_LENGTH + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The UDP checksum.
|
||||
*/
|
||||
public final int getUDPChecksum() {
|
||||
return (((_data_[__offset + OFFSET_UDP_CHECKSUM] & 0xff) << 8) |
|
||||
(_data_[__offset + OFFSET_UDP_CHECKSUM + 1] & 0xff));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The UDP packet length in bytes. This is the size of the
|
||||
* IP packet minus the size of the IP header. Normally, you want
|
||||
* this to equal the length stored in the UDP header
|
||||
* (see {@link #getUDPPacketLength}).
|
||||
*/
|
||||
public final int getUDPPacketByteLength() {
|
||||
return getIPPacketLength() - __offset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The IP header length plus the UDP header length in bytes.
|
||||
*/
|
||||
public final int getCombinedHeaderByteLength() {
|
||||
return __offset + LENGTH_UDP_HEADER;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the length of the UDP data payload.
|
||||
*
|
||||
* @param length The length of the UDP data payload in bytes.
|
||||
*/
|
||||
public final void setUDPDataByteLength(int length) {
|
||||
if(length < 0)
|
||||
length = 0;
|
||||
|
||||
setIPPacketLength(getCombinedHeaderByteLength() + length);
|
||||
}
|
||||
|
||||
|
||||
public final int getUDPDataByteLength() {
|
||||
return getIPPacketLength() - getCombinedHeaderByteLength();
|
||||
}
|
||||
|
||||
|
||||
private final int __getVirtualHeaderTotal() {
|
||||
int s1 =
|
||||
((_data_[OFFSET_SOURCE_ADDRESS] & 0xff) << 8) |
|
||||
(_data_[OFFSET_SOURCE_ADDRESS + 1] & 0xff);
|
||||
int s2 =
|
||||
((_data_[OFFSET_SOURCE_ADDRESS + 2] & 0xff) << 8) |
|
||||
(_data_[OFFSET_SOURCE_ADDRESS + 3] & 0xff);
|
||||
int d1 =
|
||||
((_data_[OFFSET_DESTINATION_ADDRESS] & 0xff) << 8) |
|
||||
(_data_[OFFSET_DESTINATION_ADDRESS + 1] & 0xff);
|
||||
int d2 =
|
||||
((_data_[OFFSET_DESTINATION_ADDRESS + 2] & 0xff) << 8) |
|
||||
(_data_[OFFSET_DESTINATION_ADDRESS + 3] & 0xff);
|
||||
return s1 + s2 + d1 + d2 + getProtocol() + getUDPPacketByteLength();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the UDP checksum, optionally updating the UDP checksum header.
|
||||
*
|
||||
* @param update Specifies whether or not to update the UDP checksum
|
||||
* header after computing the checksum. A value of true indicates
|
||||
* the header should be updated, a value of false indicates it
|
||||
* should not be updated.
|
||||
* @return The computed UDP checksum.
|
||||
*/
|
||||
public final int computeUDPChecksum(boolean update) {
|
||||
return _computeChecksum_(__offset, __offset + OFFSET_UDP_CHECKSUM,
|
||||
getIPPacketLength(), __getVirtualHeaderTotal(),
|
||||
update);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as <code>computeUDPChecksum(true);</code>
|
||||
*
|
||||
* @return The computed UDP checksum value.
|
||||
*/
|
||||
public final int computeUDPChecksum() {
|
||||
return computeUDPChecksum(true);
|
||||
}
|
||||
}
|
||||
189
ipscan/resources/Labels.txt
Executable file
@ -0,0 +1,189 @@
|
||||
icon=images/icon.gif
|
||||
encoding=ISO-8859-1
|
||||
menu.file=&File
|
||||
menu.file.saveAll=Export &results... Ctrl+S
|
||||
menu.file.saveSelection=Export &selected results...
|
||||
menu.file.exportOptions=Export &options...
|
||||
menu.file.importOptions=&Import options...
|
||||
menu.file.exit=E&xit Alt+F4
|
||||
menu.goto=&Go to
|
||||
menu.goto.aliveHost=Next alive &host Ctrl+Shift+H
|
||||
menu.goto.deadHost=Next d&ead host Ctrl+Shift+D
|
||||
menu.goto.openPort=Next open &port Ctrl+Shift+P
|
||||
menu.goto.find=Find... Ctrl+F
|
||||
menu.commands=&Commands
|
||||
menu.commands.details=&Show details Dbl-Clk
|
||||
menu.commands.rescan=&Rescan IP(s) Ctrl+R
|
||||
menu.commands.delete=&Delete IP(s) Del
|
||||
menu.commands.copy=&Copy IP Ctrl+C
|
||||
menu.commands.copyDetails=Co&py details
|
||||
menu.commands.show=Show
|
||||
menu.commands.open=Open
|
||||
menu.commands.open.edit=Edit openers...
|
||||
menu.favorites=Fa&vorites
|
||||
menu.favorites.add=Add current... Ctrl+D
|
||||
menu.favorites.edit=Manage favorites...
|
||||
menu.tools=&Tools
|
||||
menu.tools.options=&Options... Ctrl+O
|
||||
menu.tools.fetchers=Select &fetchers...
|
||||
menu.tools.delete=Delete from list
|
||||
menu.tools.lastInfo=Show last scan &info Ctrl+I
|
||||
menu.help=&Help
|
||||
menu.help.gettingStarted=Getting &Started F1
|
||||
menu.help.website=Official Website
|
||||
menu.help.forum=Forum
|
||||
menu.help.plugins=Download plugins
|
||||
menu.help.cmdLine=Command-line usage
|
||||
menu.help.checkVersion=Check for newer version...
|
||||
menu.help.about=&About... F12
|
||||
menu.columns.sortBy=Sort by
|
||||
menu.columns.sortDirection=Change sort direction
|
||||
menu.columns.info=Fetcher info
|
||||
menu.columns.options=Fetcher options
|
||||
state.ready=Ready
|
||||
state.scanning=Scanning
|
||||
state.waitForThreads=Wait for all threads to terminate...
|
||||
state.killingThreads=Killing all threads...
|
||||
state.saving=Exporting results...
|
||||
state.searching=Searching...
|
||||
state.opening=Opening
|
||||
state.retrievingVersion=Retrieving the latest version...
|
||||
title.about=About
|
||||
title.options=Options
|
||||
title.options.scanning=Scanning
|
||||
title.options.display=Display
|
||||
title.options.fetchers=Fetchers
|
||||
title.options.ports=Ports
|
||||
title.details=IP address details
|
||||
title.saveAll=Export All Results
|
||||
title.saveSelection=Export Selected Results
|
||||
title.gettingStarted=Getting Started
|
||||
title.favorite.add=Add a favorite
|
||||
title.favorite.edit=Edit favorites
|
||||
title.openers.edit=Edit Openers
|
||||
title.fetchers.select=Select Fetchers
|
||||
title.find=Find
|
||||
text.ip=IP
|
||||
text.threads=Threads:
|
||||
text.favorite.add=Enter the name of the new favorite
|
||||
text.favorite.edit=Below you can rearrange or delete favorites
|
||||
text.find=Enter the text to search for
|
||||
text.find.notFound=Nothing was found.
|
||||
text.find.restart=Would you like to start from the beginning?
|
||||
text.version.latest=You are running the latest version.
|
||||
text.version.old=The latest version is %LATEST, but you are running %VERSION.
|
||||
text.openers.edit=Below you can edit or add new openers
|
||||
text.openers.name=Opener name (menu item):
|
||||
text.openers.string=Execution string:
|
||||
text.openers.directory=Working directory:
|
||||
text.openers.inTerminal=Run the program in terminal
|
||||
text.openers.new=New opener
|
||||
text.openers.hint=&Substitutions...
|
||||
text.openers.hintText=You may use any scanned values returned by fetchers in the execution string.\n\nThe following fetchers are currently available for substitution:\n\n
|
||||
text.fetchers.select=Here you can select fetchers for scanning. Fetchers are represented by columns.
|
||||
text.fetchers.selectedList=Selected fetchers
|
||||
text.fetchers.availableList=Available fetchers
|
||||
text.about=%NAME\n\nVersion %VERSION\n%COPYLEFT\n\n<a>%WEBSITE</a>\n<a>%MAILTO</a>\n\nThis is an Open Source Software released under the GPL.
|
||||
text.gettingStarted=Dummy
|
||||
text.gettingStarted1=Angry IP Scanner is an IP address scanner tool.\n\nIt is used for scanning IP addresses for finding alive hosts, gathering any kind of needed information about each host.
|
||||
text.gettingStarted2=Main terminology:\n\nFeeder - generator of IP addresses for scanning. Angry IP Scanner provides various kinds of feeders: IP Range, Random, and IP List File. You can select a feeder using the combo box next to the "Start" button.\n\nFetcher - gathers specific information about a host, e.g. ping time, hostname, open ports. Feeders usually represent columns in the scanning results list.
|
||||
button.OK=OK
|
||||
button.cancel=Cancel
|
||||
button.close=Close
|
||||
button.next=Next ->
|
||||
button.start.img=images/buttons/start.gif
|
||||
button.stop.img=images/buttons/stop.gif
|
||||
button.kill.img=images/buttons/kill.gif
|
||||
button.ipUp.img=images/buttons/ipup.gif
|
||||
button.up=&Up
|
||||
button.down=&Down
|
||||
button.delete=De&lete
|
||||
button.save=&Save
|
||||
button.insert=&Insert
|
||||
button.add=&Add
|
||||
button.left=<
|
||||
button.right=>
|
||||
combobox.feeder.tooltip=IP Feeder selection. Change this if you need another source for IP addresses to scan
|
||||
list.unknown.img=images/list/unknown.gif
|
||||
list.dead.img=images/list/dead.gif
|
||||
list.alive.img=images/list/alive.gif
|
||||
list.addinfo.img=images/list/addinfo.gif
|
||||
pinger.icmp=ICMP Echo
|
||||
pinger.icmp2=ICMP Echo (Alternative)
|
||||
pinger.udp=UDP packet
|
||||
pinger.tcp=TCP port probe
|
||||
opener.web=Web Browser
|
||||
opener.ftp=FTP
|
||||
opener.telnet=Telnet
|
||||
opener.ssh=SSH
|
||||
opener.netbios=Windows Shares
|
||||
opener.email=E-mail sample
|
||||
feeder.range=IP Range
|
||||
feeder.range.startIP=IP Range:
|
||||
feeder.range.endIP=to
|
||||
feeder.range.netmask=Netmask
|
||||
feeder.range.netmask.tooltip=Netmask of the IP range. Use either number of bits (e.g. /24) or the dotted notation (.255. = ..)
|
||||
feeder.range.hostname=Hostname:
|
||||
feeder.range.hostname.tooltip=Use this field to resolve hostnames to IP addresses
|
||||
feeder.file=IP List File
|
||||
feeder.file.name=Filename
|
||||
feeder.file.browse=Browse...
|
||||
feeder.random=Random
|
||||
feeder.random.prototype=Base IP:
|
||||
feeder.random.mask=IP Mask:
|
||||
feeder.random.hostname=Hostname:
|
||||
feeder.random.count=Count:
|
||||
fetcher.ip=IP
|
||||
fetcher.ping=Ping
|
||||
fetcher.ping.ttl=TTL
|
||||
fetcher.hostname=Hostname
|
||||
fetcher.ports=Ports
|
||||
fetcher.ports.filtered=Filtered Ports
|
||||
fetcher.value.ms= ms
|
||||
fetcher.value.notAvailable=[n/a]
|
||||
fetcher.value.notScanned=[n/s]
|
||||
options.threads=Threads
|
||||
options.threads.delay=Delay between starting threads (in ms):
|
||||
options.threads.maxThreads=Maximum number of threads:
|
||||
options.pinging.deadHosts=Scan dead hosts, which don't reply to pings
|
||||
options.pinging=Pinging
|
||||
options.pinging.type=Pinging method:
|
||||
options.pinging.count=Number of ping probes (packets to send):
|
||||
options.pinging.timeout=Ping timeout (in ms):
|
||||
options.broadcast=Broadcast
|
||||
options.broadcast.skip=Skip likely broadcast IP addresses
|
||||
options.fetchers.info=Here you can change options, specific to fetchers
|
||||
options.ports.timing=Timing
|
||||
options.ports.timing.timeout=Default port connect timeout (in ms):
|
||||
options.ports.timing.adaptTimeout=Adapt timeout to ping roundtrip time (if available)
|
||||
options.ports.ports=Port selection
|
||||
options.ports.portsDescription=Specify ports to scan here. Ranges are supported.\nExample: 1-3,5,7,10-15,6000-6100\nIf many ports are specified, scanning can take a lot of time.
|
||||
exporter.txt=Text file (txt)
|
||||
exporter.txt.generated=Generated by
|
||||
exporter.txt.scanned=Scanned %INFO
|
||||
exporter.csv=Comma-separated file (csv)
|
||||
exporter.xml=XML file
|
||||
exporter.ipList=IP:List file (lst)
|
||||
exception.FeederException.invalidNetmask=Invalid netmask specified. Must be in the A.B.C.D format
|
||||
exception.FeederException.invalidHostname=Invalid or inexistent hostname specified
|
||||
exception.FeederException.malformedIP=Malformed IP address specified, it should look like A.B.C.D
|
||||
exception.FeederException.range.greaterThan=The starting IP should be lower than the ending IP
|
||||
exception.FeederException.random.invalidCount=Random address count must be greater than 0
|
||||
exception.FeederException.file.notExists=Specified file doesn't exist or you don't have permissions to read it
|
||||
exception.FeederException.file.errorWhileReading=Error while reading the file
|
||||
exception.FeederException.file.nothingFound=No IP addresses found in the file
|
||||
exception.ExporterException.failed=Exporting failed
|
||||
exception.ExporterException.exporter.unknown=Unknown file type, please specify correct extension in the file name.
|
||||
exception.ExporterException.xml.noAppend=Appending to XML files is not supported.
|
||||
exception.ExporterException.fetcher.notFound=Not enough data in the scanning results to export to this file type.
|
||||
exception.UserErrorException.openURL.failed=Unable to launch your default browser, sorry.\nURL:
|
||||
exception.UserErrorException.openTerminal.failed=Unable to launch the terminal, sorry\n
|
||||
exception.UserErrorException.opener.failed=Unable to launch an external process, sorry.\nCommand-line:
|
||||
exception.UserErrorException.opener.unknownFetcher=The referenced fetcher cannot be resolved in the current scanning result. Cannot execute the opener with parameter:
|
||||
exception.UserErrorException.opener.nullFetcherValue=The replacement value of the fetcher is empty in the scanning results. Cannot execute the opener with parameter:
|
||||
exception.UserErrorException.opener.edit.noSelection=Please select the position where do you want to save your opener and or the Insert button to add a new one.
|
||||
exception.UserErrorException.commands.noSelection=No IP address selected
|
||||
exception.UserErrorException.commands.noResults=No scanning results available yet, please perform a scan first
|
||||
exception.UserErrorException.favorite.alreadyExists=A favorite with the same name already exists, please try a different one
|
||||
exception.UserErrorException.version.latestFailed=Failed to retrieve the latest version. Please visit the website manually.
|
||||
exception.OutOfMemoryError=Out Of Memory. The amount of available to the program heap memory has been exceeded.\nPlease increase the maximum heap size for this program.
|
||||
BIN
ipscan/resources/images/buttons/ipup.gif
Executable file
|
After Width: | Height: | Size: 128 B |
BIN
ipscan/resources/images/buttons/kill.gif
Executable file
|
After Width: | Height: | Size: 160 B |
BIN
ipscan/resources/images/buttons/start.gif
Executable file
|
After Width: | Height: | Size: 154 B |
BIN
ipscan/resources/images/buttons/stop.gif
Executable file
|
After Width: | Height: | Size: 157 B |
BIN
ipscan/resources/images/icon.gif
Executable file
|
After Width: | Height: | Size: 257 B |
BIN
ipscan/resources/images/list/addinfo.gif
Executable file
|
After Width: | Height: | Size: 99 B |
BIN
ipscan/resources/images/list/alive.gif
Executable file
|
After Width: | Height: | Size: 113 B |
BIN
ipscan/resources/images/list/dead.gif
Executable file
|
After Width: | Height: | Size: 99 B |
BIN
ipscan/resources/images/list/unknown.gif
Executable file
|
After Width: | Height: | Size: 94 B |
120
ipscan/src/net/azib/ipscan/Main.java
Executable file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan;
|
||||
|
||||
import java.security.Security;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import net.azib.ipscan.config.Config;
|
||||
import net.azib.ipscan.config.GUIComponentContainer;
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.gui.MainWindow;
|
||||
import net.azib.ipscan.gui.UserErrorException;
|
||||
|
||||
/**
|
||||
* The main executable class.
|
||||
* It initializes all the needed stuff and launches the user interface.
|
||||
*
|
||||
* All Exceptions, which are thrown out of the program, are catched and logged
|
||||
* using the java.util.logging facilities.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Logger.global.setLevel(Level.CONFIG);
|
||||
|
||||
initProperties();
|
||||
|
||||
Display display = Display.getDefault();
|
||||
|
||||
// initalize Labels instance
|
||||
Labels.initialize(new Locale("en")); // TODO: retrieve locale normally
|
||||
|
||||
// initialize Config instance
|
||||
Config.initialize();
|
||||
|
||||
// create the main window using dependency injection
|
||||
MainWindow mainWindow = new GUIComponentContainer().createMainWindow();
|
||||
|
||||
while (!mainWindow.isDisposed()) {
|
||||
try {
|
||||
if (!display.readAndDispatch())
|
||||
display.sleep();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
// display a nice error message
|
||||
String localizedMessage = getLocalizedMessage(e);
|
||||
Shell parent = display.getActiveShell();
|
||||
MessageBox messageBox = new MessageBox(parent != null ? parent : mainWindow.getShell(), SWT.OK | SWT.ICON_ERROR);
|
||||
messageBox.setText("Error");
|
||||
messageBox.setMessage(localizedMessage);
|
||||
messageBox.open();
|
||||
}
|
||||
}
|
||||
|
||||
// save config on exit
|
||||
Config.store();
|
||||
|
||||
// dispose the native objects
|
||||
display.dispose();
|
||||
}
|
||||
|
||||
private static void initProperties() {
|
||||
// currently we support IPv4 only
|
||||
System.setProperty("java.net.preferIPv4Stack", "true");
|
||||
// disable DNS caches
|
||||
Security.setProperty("networkaddress.cache.ttl", "0");
|
||||
Security.setProperty("networkaddress.cache.negative.ttl", "0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a nice localized message for the passed exception
|
||||
* in case it is possible, or toString() otherwise.
|
||||
*/
|
||||
static String getLocalizedMessage(Throwable e) {
|
||||
String localizedMessage;
|
||||
try {
|
||||
// try to load localized message
|
||||
if (e instanceof UserErrorException) {
|
||||
localizedMessage = e.getMessage();
|
||||
}
|
||||
else {
|
||||
String exceptionClassName = getClassShortName(e.getClass());
|
||||
String originalMessage = e.getMessage();
|
||||
localizedMessage = Labels.getLabel("exception." + exceptionClassName + (originalMessage != null ? "." + originalMessage : ""));
|
||||
}
|
||||
// add cause summary, if it exists
|
||||
if (e.getCause() != null) {
|
||||
localizedMessage += "\n\n" + e.getCause().toString();
|
||||
}
|
||||
Logger.global.log(Level.FINE, "error", e);
|
||||
}
|
||||
catch (Exception e2) {
|
||||
// fallback to default text
|
||||
localizedMessage = e.toString();
|
||||
// output stack trace to the console
|
||||
Logger.global.log(Level.SEVERE, "unexpected error", e);
|
||||
}
|
||||
return localizedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the short name of a class (without package name)
|
||||
*/
|
||||
static String getClassShortName(Class clazz) {
|
||||
String className = clazz.getName();
|
||||
return className.substring(className.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
}
|
||||
80
ipscan/src/net/azib/ipscan/config/Config.java
Executable file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* This class encapsulates configuration options of the program.
|
||||
* It is a singleton class.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public final class Config {
|
||||
|
||||
private static Preferences preferences;
|
||||
|
||||
/** easily accessible global configuration */
|
||||
private static GlobalConfig globalConfig;
|
||||
/** favorites are stored here */
|
||||
private static NamedListConfig favoritesConfig;
|
||||
/** openers are stored here */
|
||||
private static OpenersConfig openersConfig;
|
||||
/** various dimensions are stored here */
|
||||
private static DimensionsConfig dimensionsConfig;
|
||||
|
||||
private Config() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the singleton instance
|
||||
*/
|
||||
public static void initialize() {
|
||||
preferences = Preferences.userRoot().node("ipscan");
|
||||
globalConfig = new GlobalConfig();
|
||||
favoritesConfig = new FavoritesConfig();
|
||||
openersConfig = new OpenersConfig();
|
||||
dimensionsConfig = new DimensionsConfig();
|
||||
}
|
||||
|
||||
public static void store() {
|
||||
globalConfig.store();
|
||||
favoritesConfig.store();
|
||||
openersConfig.store();
|
||||
dimensionsConfig.store();
|
||||
}
|
||||
|
||||
public static Preferences getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GlobalConfig instance (quick access)
|
||||
*/
|
||||
public static GlobalConfig getGlobal() {
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Favorites config (quick access);
|
||||
*/
|
||||
public static NamedListConfig getFavoritesConfig() {
|
||||
return favoritesConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Openers config (quick access);
|
||||
*/
|
||||
public static OpenersConfig getOpenersConfig() {
|
||||
return openersConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Dimensions config (quick access);
|
||||
*/
|
||||
public static DimensionsConfig getDimensionsConfig() {
|
||||
return dimensionsConfig;
|
||||
}
|
||||
|
||||
}
|
||||
96
ipscan/src/net/azib/ipscan/config/DimensionsConfig.java
Executable file
@ -0,0 +1,96 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
|
||||
/**
|
||||
* DimensionsConfig
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class DimensionsConfig {
|
||||
|
||||
private Preferences preferences;
|
||||
|
||||
public int windowHeight;
|
||||
public int windowWidth;
|
||||
public int windowTop;
|
||||
public int windowLeft;
|
||||
public boolean isWindowMaximized;
|
||||
|
||||
// package local constructor
|
||||
DimensionsConfig() {
|
||||
preferences = Config.getPreferences();
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is for tests
|
||||
* @param preferences
|
||||
*/
|
||||
DimensionsConfig(Preferences preferences) {
|
||||
this.preferences = preferences;
|
||||
load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
windowHeight = preferences.getInt("windowHeight", 350);
|
||||
windowWidth = preferences.getInt("windowWidth", 560);
|
||||
windowTop = preferences.getInt("windowTop", 100);
|
||||
windowLeft = preferences.getInt("windowLeft", 100);
|
||||
isWindowMaximized = preferences.getBoolean("windowMaximized", false);
|
||||
}
|
||||
|
||||
public void store() {
|
||||
if (!isWindowMaximized) {
|
||||
preferences.putInt("windowHeight", windowHeight);
|
||||
preferences.putInt("windowWidth", windowWidth);
|
||||
preferences.putInt("windowTop", windowTop);
|
||||
preferences.putInt("windowLeft", windowLeft);
|
||||
}
|
||||
preferences.putBoolean("windowMaximized", isWindowMaximized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Rectangle getWindowBounds() {
|
||||
return new Rectangle(windowLeft, windowTop, windowWidth, windowHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bounds
|
||||
* @param isMaximized
|
||||
*/
|
||||
public void setWindowBounds(Rectangle bounds, boolean isMaximized) {
|
||||
if (!isMaximized) {
|
||||
windowTop = bounds.y;
|
||||
windowLeft = bounds.x;
|
||||
windowHeight = bounds.height;
|
||||
windowWidth = bounds.width;
|
||||
}
|
||||
isWindowMaximized = isMaximized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fetcherName
|
||||
* @return column width corresponding to a fetcher
|
||||
*/
|
||||
public int getColumnWidth(String fetcherName) {
|
||||
return preferences.getInt("columnWidth." + fetcherName, 90);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the width of a column corresponding to a fetcher
|
||||
* @param fetcherName
|
||||
* @param width
|
||||
*/
|
||||
public void setColumnWidth(String fetcherName, int width) {
|
||||
preferences.putInt("columnWidth." + fetcherName, width);
|
||||
}
|
||||
|
||||
}
|
||||
17
ipscan/src/net/azib/ipscan/config/FavoritesConfig.java
Executable file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
/**
|
||||
* FavoritesConfig
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class FavoritesConfig extends NamedListConfig {
|
||||
|
||||
public FavoritesConfig() {
|
||||
super("favorites");
|
||||
}
|
||||
|
||||
}
|
||||
161
ipscan/src/net/azib/ipscan/config/GUIComponentContainer.java
Executable file
@ -0,0 +1,161 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import net.azib.ipscan.core.Scanner;
|
||||
import net.azib.ipscan.core.ScannerThreadFactory;
|
||||
import net.azib.ipscan.core.ScanningResultList;
|
||||
import net.azib.ipscan.core.net.PingerRegistry;
|
||||
import net.azib.ipscan.core.net.PingerRegistryImpl;
|
||||
import net.azib.ipscan.exporters.CSVExporter;
|
||||
import net.azib.ipscan.exporters.ExporterRegistry;
|
||||
import net.azib.ipscan.exporters.IPListExporter;
|
||||
import net.azib.ipscan.exporters.TXTExporter;
|
||||
import net.azib.ipscan.exporters.XMLExporter;
|
||||
import net.azib.ipscan.fetchers.FetcherRegistry;
|
||||
import net.azib.ipscan.fetchers.FetcherRegistryImpl;
|
||||
import net.azib.ipscan.fetchers.FilteredPortsFetcher;
|
||||
import net.azib.ipscan.fetchers.HostnameFetcher;
|
||||
import net.azib.ipscan.fetchers.IPFetcher;
|
||||
import net.azib.ipscan.fetchers.PingFetcher;
|
||||
import net.azib.ipscan.fetchers.PingTTLFetcher;
|
||||
import net.azib.ipscan.fetchers.PortsFetcher;
|
||||
import net.azib.ipscan.gui.MainMenu;
|
||||
import net.azib.ipscan.gui.MainWindow;
|
||||
import net.azib.ipscan.gui.OptionsWindow;
|
||||
import net.azib.ipscan.gui.ResultTable;
|
||||
import net.azib.ipscan.gui.SelectFetchersDialog;
|
||||
import net.azib.ipscan.gui.StatusBar;
|
||||
import net.azib.ipscan.gui.MainMenu.CommandsMenu;
|
||||
import net.azib.ipscan.gui.actions.ColumnsActions;
|
||||
import net.azib.ipscan.gui.actions.OpenerLauncher;
|
||||
import net.azib.ipscan.gui.actions.StartStopScanningAction;
|
||||
import net.azib.ipscan.gui.feeders.FeederGUIRegistry;
|
||||
import net.azib.ipscan.gui.feeders.FileFeederGUI;
|
||||
import net.azib.ipscan.gui.feeders.RandomFeederGUI;
|
||||
import net.azib.ipscan.gui.feeders.RangeFeederGUI;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
import org.picocontainer.Parameter;
|
||||
import org.picocontainer.PicoContainer;
|
||||
import org.picocontainer.defaults.ComponentParameter;
|
||||
import org.picocontainer.defaults.ConstantParameter;
|
||||
import org.picocontainer.defaults.DefaultPicoContainer;
|
||||
|
||||
/**
|
||||
* This class is a dependency injection configuration
|
||||
* using the Pico Container.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class GUIComponentContainer {
|
||||
|
||||
private PicoContainer container;
|
||||
|
||||
public GUIComponentContainer() {
|
||||
MutablePicoContainer container = new DefaultPicoContainer();
|
||||
this.container = container;
|
||||
|
||||
ComponentParameter anyComponentParameter = new ComponentParameter();
|
||||
|
||||
// non-GUI TODO: move to a separate container
|
||||
container.registerComponentImplementation(ExporterRegistry.class);
|
||||
container.registerComponentImplementation(TXTExporter.class);
|
||||
container.registerComponentImplementation(CSVExporter.class);
|
||||
container.registerComponentImplementation(XMLExporter.class);
|
||||
container.registerComponentImplementation(IPListExporter.class);
|
||||
|
||||
container.registerComponentImplementation(FetcherRegistry.class, FetcherRegistryImpl.class);
|
||||
container.registerComponentImplementation(IPFetcher.class);
|
||||
container.registerComponentImplementation(PingFetcher.class);
|
||||
container.registerComponentImplementation(PingTTLFetcher.class);
|
||||
container.registerComponentImplementation(HostnameFetcher.class);
|
||||
container.registerComponentImplementation(PortsFetcher.class);
|
||||
container.registerComponentImplementation(FilteredPortsFetcher.class);
|
||||
|
||||
container.registerComponentImplementation(PingerRegistry.class, PingerRegistryImpl.class);
|
||||
container.registerComponentImplementation(ScanningResultList.class);
|
||||
container.registerComponentImplementation(Scanner.class);
|
||||
container.registerComponentImplementation(ScannerThreadFactory.class);
|
||||
|
||||
// GUI follows
|
||||
|
||||
// Some "shared" GUI components
|
||||
container.registerComponentImplementation("mainShell", Shell.class);
|
||||
container.registerComponentImplementation("mainMenu", Menu.class, new Parameter[] {
|
||||
new ComponentParameter("mainShell"),
|
||||
new ConstantParameter(new Integer(SWT.BAR))});
|
||||
container.registerComponentImplementation("commandsMenu", CommandsMenu.class);
|
||||
|
||||
container.registerComponentImplementation("feederArea", Composite.class, new Parameter[] {
|
||||
new ComponentParameter("mainShell"),
|
||||
new ConstantParameter(new Integer(SWT.NONE))});
|
||||
container.registerComponentImplementation("controlsArea", Composite.class, new Parameter[] {
|
||||
new ComponentParameter("mainShell"),
|
||||
new ConstantParameter(new Integer(SWT.NONE))});
|
||||
container.registerComponentImplementation("startStopButton", Button.class, new Parameter[] {
|
||||
new ComponentParameter("controlsArea"),
|
||||
new ConstantParameter(new Integer(SWT.NONE))});
|
||||
container.registerComponentImplementation("feederSelectionCombo", Combo.class, new Parameter[] {
|
||||
new ComponentParameter("controlsArea"),
|
||||
new ConstantParameter(new Integer(SWT.READ_ONLY))});
|
||||
|
||||
// GUI Feeders
|
||||
container.registerComponentImplementation(FeederGUIRegistry.class);
|
||||
Parameter[] feederGUIParameters = new Parameter[] {new ComponentParameter("feederArea")};
|
||||
container.registerComponentImplementation(RangeFeederGUI.class, RangeFeederGUI.class, feederGUIParameters);
|
||||
container.registerComponentImplementation(RandomFeederGUI.class, RandomFeederGUI.class, feederGUIParameters);
|
||||
container.registerComponentImplementation(FileFeederGUI.class, FileFeederGUI.class, feederGUIParameters);
|
||||
|
||||
container.registerComponentImplementation(OpenerLauncher.class);
|
||||
container.registerComponentImplementation(MainWindow.class, MainWindow.class, new Parameter[] {
|
||||
new ComponentParameter("mainShell"),
|
||||
new ComponentParameter("feederArea"),
|
||||
new ComponentParameter("controlsArea"),
|
||||
new ComponentParameter("feederSelectionCombo"),
|
||||
new ComponentParameter("startStopButton"),
|
||||
anyComponentParameter,
|
||||
anyComponentParameter,
|
||||
anyComponentParameter,
|
||||
anyComponentParameter,
|
||||
anyComponentParameter});
|
||||
container.registerComponentImplementation(ResultTable.class, ResultTable.class, new Parameter[] {
|
||||
new ComponentParameter("mainShell"),
|
||||
anyComponentParameter,
|
||||
anyComponentParameter,
|
||||
anyComponentParameter});
|
||||
container.registerComponentImplementation(StatusBar.class, StatusBar.class, new Parameter[] {
|
||||
new ComponentParameter("mainShell")});
|
||||
|
||||
container.registerComponentImplementation(MainMenu.class, MainMenu.class, new Parameter[] {
|
||||
new ComponentParameter("mainShell"),
|
||||
new ComponentParameter("mainMenu"),
|
||||
new ComponentParameter("commandsMenu"),
|
||||
new ConstantParameter(container)});
|
||||
container.registerComponentImplementation(MainMenu.ColumnsMenu.class, MainMenu.ColumnsMenu.class, new Parameter[] {
|
||||
new ComponentParameter("mainShell"),
|
||||
anyComponentParameter});
|
||||
|
||||
container.registerComponentImplementation(OptionsWindow.class);
|
||||
container.registerComponentImplementation(SelectFetchersDialog.class);
|
||||
|
||||
// various actions / listener
|
||||
container.registerComponentImplementation(StartStopScanningAction.class);
|
||||
container.registerComponentImplementation(ColumnsActions.SortBy.class);
|
||||
}
|
||||
|
||||
public MainWindow createMainWindow() {
|
||||
// initialize the main menu
|
||||
container.getComponentInstance(MainMenu.class);
|
||||
// initialize and return the main window
|
||||
return (MainWindow) container.getComponentInstance(MainWindow.class);
|
||||
}
|
||||
|
||||
}
|
||||
61
ipscan/src/net/azib/ipscan/config/GlobalConfig.java
Executable file
@ -0,0 +1,61 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* Global configuration holder.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public final class GlobalConfig {
|
||||
|
||||
private static final String MAX_THREADS = "maxThreads";
|
||||
private static final String THREAD_DELAY = "threadDelay";
|
||||
private static final String ACTIVE_FEEDER = "activeFeeder";
|
||||
private static final String SCAN_DEAD_HOSTS = "scanDeadHosts";
|
||||
private static final String SELECTED_PINGER = "selectedPinger";
|
||||
private static final String PING_TIMEOUT = "pingTimeout";
|
||||
private static final String PING_COUNT = "pingCount";
|
||||
private static final String SKIP_BROADCAST_ADDRESSES = "skipBroadcastAddresses";
|
||||
private static final String PORT_TIMEOUT = "portTimeout";
|
||||
private static final String ADAPT_PORT_TIMEOUT = "adaptPortTimeout";
|
||||
private static final String PORT_STRING = "portString";
|
||||
|
||||
private Preferences preferences = Config.getPreferences();
|
||||
|
||||
public int maxThreads = preferences.getInt(MAX_THREADS, 100);
|
||||
public int threadDelay = preferences.getInt(THREAD_DELAY, 20);
|
||||
public int activeFeeder = preferences.getInt(ACTIVE_FEEDER, 0);
|
||||
public boolean scanDeadHosts = preferences.getBoolean(SCAN_DEAD_HOSTS, false);
|
||||
public String selectedPinger = preferences.get(SELECTED_PINGER, "pinger.icmp");
|
||||
public int pingTimeout = preferences.getInt(PING_TIMEOUT, 3000);
|
||||
public int pingCount = preferences.getInt(PING_COUNT, 3);
|
||||
public boolean skipBroadcastAddresses = preferences.getBoolean(SKIP_BROADCAST_ADDRESSES, true);
|
||||
public int portTimeout = preferences.getInt(PORT_TIMEOUT, 3000);;
|
||||
public boolean adaptPortTimeout = preferences.getBoolean(ADAPT_PORT_TIMEOUT, true);
|
||||
public String portString = preferences.get(PORT_STRING, "");
|
||||
|
||||
/**
|
||||
* Stores all the internal properties to the storage media
|
||||
*/
|
||||
public void store() {
|
||||
preferences.putInt(MAX_THREADS, maxThreads);
|
||||
preferences.putInt(THREAD_DELAY, threadDelay);
|
||||
preferences.putInt(ACTIVE_FEEDER, activeFeeder);
|
||||
preferences.putBoolean(SCAN_DEAD_HOSTS, scanDeadHosts);
|
||||
preferences.put(SELECTED_PINGER, selectedPinger);
|
||||
preferences.putInt(PING_TIMEOUT, pingTimeout);
|
||||
preferences.putInt(PING_COUNT, pingCount);
|
||||
preferences.putBoolean(SKIP_BROADCAST_ADDRESSES, skipBroadcastAddresses);
|
||||
preferences.putInt(PORT_TIMEOUT, portTimeout);
|
||||
preferences.putBoolean(ADAPT_PORT_TIMEOUT, adaptPortTimeout);
|
||||
preferences.put(PORT_STRING, portString);
|
||||
}
|
||||
|
||||
// package local constructor
|
||||
GlobalConfig() {
|
||||
}
|
||||
}
|
||||
98
ipscan/src/net/azib/ipscan/config/Labels.java
Executable file
@ -0,0 +1,98 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.PropertyResourceBundle;
|
||||
|
||||
/**
|
||||
* Labels class for localization, based on PropertyResourceBundle.
|
||||
* It adds some special methods for loading of images by IDs.
|
||||
*
|
||||
* It is a singleton, so use getInstance() in order to use this class.
|
||||
*
|
||||
* Use initialize() to create an instance of this class.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public final class Labels {
|
||||
|
||||
private static Labels instance;
|
||||
|
||||
PropertyResourceBundle labels;
|
||||
Locale locale;
|
||||
|
||||
static {
|
||||
// this is needed for Visual Editor to display
|
||||
// labels at design time
|
||||
initialize(new Locale("en"));
|
||||
}
|
||||
|
||||
private Labels() {
|
||||
// private constructor
|
||||
}
|
||||
|
||||
public static final Labels getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialized the internal locale-specific data.
|
||||
* The files Labels_LANG.txt and Labels.txt are searched for
|
||||
* in the same package as this class.
|
||||
* This method must be called prior to using this class.
|
||||
*/
|
||||
public static void initialize(Locale locale) {
|
||||
if (instance != null && locale.equals(instance.locale)) {
|
||||
// do not reload locale, because it was already initialized in the static block
|
||||
return;
|
||||
}
|
||||
// create a new instance
|
||||
instance = new Labels();
|
||||
|
||||
instance.locale = locale;
|
||||
InputStream labelsStream = null;
|
||||
labelsStream = Labels.class.getClassLoader().getResourceAsStream("Labels_" + locale.getLanguage().toUpperCase() + ".txt");
|
||||
if (labelsStream == null) {
|
||||
labelsStream = Labels.class.getClassLoader().getResourceAsStream("Labels.txt");
|
||||
}
|
||||
if (labelsStream == null) {
|
||||
throw new MissingResourceException("Labels not found!", Labels.class.getName(), "Labels");
|
||||
}
|
||||
try {
|
||||
instance.labels = new PropertyResourceBundle(labelsStream);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new MissingResourceException(e.toString(), Labels.class.getName(), "Labels");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an InputStream to load the image, specified by a key in resource file.
|
||||
* @param key
|
||||
*/
|
||||
public InputStream getImageAsStream(String key) {
|
||||
String imagePath = labels.getString(key);
|
||||
return getClass().getClassLoader().getResourceAsStream(imagePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a String specified by the label key
|
||||
* @param key
|
||||
*/
|
||||
public String get(String key) {
|
||||
return labels.getString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* A shortened form of Labels.getLabel()
|
||||
*/
|
||||
public static String getLabel(String key) {
|
||||
return getInstance().get(key);
|
||||
}
|
||||
|
||||
}
|
||||
117
ipscan/src/net/azib/ipscan/config/NamedListConfig.java
Executable file
@ -0,0 +1,117 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* This is a generic named list config.
|
||||
* Can be used for storing favorites, openers, and other
|
||||
* user-defined configurations.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class NamedListConfig {
|
||||
|
||||
protected String preferenceName;
|
||||
protected Preferences preferences = Config.getPreferences();
|
||||
protected Map namedList = new LinkedHashMap();
|
||||
|
||||
// package local constructor
|
||||
NamedListConfig(String preferenceName) {
|
||||
this.preferenceName = preferenceName;
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is for tests
|
||||
* @param preferences
|
||||
*/
|
||||
NamedListConfig(Preferences preferences, String preferenceName) {
|
||||
this.preferenceName = preferenceName;
|
||||
this.preferences = preferences;
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads preferences
|
||||
*/
|
||||
public void load() {
|
||||
if (preferences == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] namedListPrefs = preferences.get(preferenceName, "").split("###");
|
||||
for (int i = 0; i < namedListPrefs.length; i += 2) {
|
||||
if (namedListPrefs[i].length() > 0) {
|
||||
namedList.put(namedListPrefs[i], serializeValue(namedListPrefs[i+1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object serializeValue(String value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the currently available named list
|
||||
*/
|
||||
public void store() {
|
||||
StringBuffer sb = new StringBuffer(32);
|
||||
for (Iterator i = namedList.entrySet().iterator(); i.hasNext();) {
|
||||
Map.Entry e = (Map.Entry) i.next();
|
||||
sb.append(e.getKey()).append("###").append(e.getValue()).append("###");
|
||||
}
|
||||
if (sb.length() > 3) {
|
||||
sb.delete(sb.length() - 3, sb.length());
|
||||
}
|
||||
preferences.put(preferenceName, sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name displayed to the user
|
||||
* @param value to store according to the name
|
||||
*/
|
||||
public void add(String name, Object value) {
|
||||
namedList.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name name
|
||||
* @return stored value
|
||||
*/
|
||||
public String get(String name) {
|
||||
return (String) namedList.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an Iterator for iterating names of available items
|
||||
*/
|
||||
public Iterator iterateNames() {
|
||||
return namedList.keySet().iterator();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return namedList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the list, retaining only items that are passed in the array.
|
||||
* The order of elements will be the same as in the array.
|
||||
*
|
||||
* @param names
|
||||
*/
|
||||
public void update(String[] names) {
|
||||
// rebuild the map (to recreate the new order of elements)
|
||||
Map newList = new LinkedHashMap();
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
newList.put(names[i], namedList.get(names[i]));
|
||||
}
|
||||
namedList = newList;
|
||||
}
|
||||
|
||||
}
|
||||
87
ipscan/src/net/azib/ipscan/config/OpenersConfig.java
Executable file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* OpenersConfig
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class OpenersConfig extends NamedListConfig {
|
||||
|
||||
public OpenersConfig() {
|
||||
super("openers");
|
||||
|
||||
if (size() == 0) {
|
||||
boolean isWindows = System.getProperty("os.name").startsWith("Windows");
|
||||
|
||||
Labels labels = Labels.getInstance();
|
||||
// add default openers
|
||||
if (isWindows) add(labels.get("opener.netbios"), new Opener("\\\\${fetcher.ip}", false, null));
|
||||
add(labels.get("opener.web"), new Opener("http://${fetcher.ip}/", false, null));
|
||||
add(labels.get("opener.ftp"), new Opener("ftp://${fetcher.ip}/", false, null));
|
||||
add(labels.get("opener.telnet"), new Opener("telnet ${fetcher.ip}", true, null));
|
||||
if (!isWindows) add(labels.get("opener.ssh"), new Opener("ssh ${fetcher.ip}", true, null));
|
||||
add(labels.get("opener.email"), new Opener("mailto:somebody@example.com?subject=IP: ${fetcher.ip}", true, null));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is for tests
|
||||
* @param preferences
|
||||
*/
|
||||
OpenersConfig(Preferences preferences) {
|
||||
super(preferences, "openers");
|
||||
}
|
||||
|
||||
Object serializeValue(String value) {
|
||||
return new Opener(value);
|
||||
}
|
||||
|
||||
public void add(String name, Object value) {
|
||||
if (value instanceof Opener)
|
||||
super.add(name, value);
|
||||
else
|
||||
// ensure only Openers are allowed here
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public Opener getOpener(String name) {
|
||||
return (Opener)namedList.get(name);
|
||||
}
|
||||
|
||||
public static class Opener {
|
||||
public String execString;
|
||||
public boolean inTerminal;
|
||||
public File workingDir;
|
||||
|
||||
Opener(String serialized) {
|
||||
try {
|
||||
String[] parts = serialized.split("@@@");
|
||||
execString = parts[0];
|
||||
inTerminal = parts[1].charAt(0) == '1';
|
||||
workingDir = parts.length >= 3 && parts[2].length() > 0 ? new File(parts[2]) : null;
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
// this happens when broken settings have been loaded
|
||||
Logger.global.fine("Broken opener config read: " + serialized);
|
||||
}
|
||||
}
|
||||
|
||||
public Opener(String execString, boolean inTerminal, File workingDir) {
|
||||
this.execString = execString;
|
||||
this.inTerminal = inTerminal;
|
||||
this.workingDir = workingDir;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return execString + "@@@" + (inTerminal ? '1' : '0') + "@@@" + (workingDir != null ? workingDir.toString() : "");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
30
ipscan/src/net/azib/ipscan/config/Version.java
Executable file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* This is a part of Angry IP Scanner source.
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
/**
|
||||
* Class with accessors to version information of the program.
|
||||
*
|
||||
* @author anton
|
||||
* @version $Id: Version.java,v 1.2 2005/11/20 14:08:28 angryziber Exp $
|
||||
*/
|
||||
public class Version {
|
||||
public static final String NAME = "Angry IP Scanner";
|
||||
|
||||
public static final String VERSION = "2.9-alpha";
|
||||
|
||||
public static final String FULL_NAME = NAME + " " + VERSION;
|
||||
|
||||
public static final String COPYLEFT = "(C) 1998-2006 Anton Keks";
|
||||
|
||||
public static final String WEBSITE = "http://www.azib.net/ipscan/";
|
||||
|
||||
public static final String MAILTO = "support@azib.net";
|
||||
|
||||
public static final String FORUM_URL = "http://www.azib.net/ipscan/forum/";
|
||||
|
||||
public static final String PLUGINS_URL = "http://www.azib.net/ipscan/plugins/";
|
||||
|
||||
public static final String LATEST_VERSION_URL = "http://www.azib.net/ipscan/IPSCAN.VERSION";
|
||||
}
|
||||
160
ipscan/src/net/azib/ipscan/core/InetAddressUtils.java
Executable file
@ -0,0 +1,160 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* This class provides various utility static methods,
|
||||
* useful for transforming InetAddress objects.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class InetAddressUtils {
|
||||
|
||||
// Warning! IPv4 specific code
|
||||
public static final Pattern IP_ADDRESS_REGEX = Pattern.compile("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
|
||||
|
||||
public static InetAddress startRangeByNetmask(InetAddress address, InetAddress netmask) {
|
||||
byte[] netmaskBytes = netmask.getAddress();
|
||||
byte[] addressBytes = address.getAddress();
|
||||
for (int i = 0; i < addressBytes.length; i++) {
|
||||
addressBytes[i] = (byte) (addressBytes[i] & netmaskBytes[i]);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(addressBytes);
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
// this should never happen as we are modifying the same bytes
|
||||
// received from the InetAddress
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static InetAddress endRangeByNetmask(InetAddress address, InetAddress netmask) {
|
||||
byte[] netmaskBytes = netmask.getAddress();
|
||||
byte[] addressBytes = address.getAddress();
|
||||
for (int i = 0; i < addressBytes.length; i++) {
|
||||
addressBytes[i] = (byte) (addressBytes[i] | ~(netmaskBytes[i]));
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(addressBytes);
|
||||
} catch (UnknownHostException e) {
|
||||
// this should never happen as we are modifying the same bytes
|
||||
// received from the InetAddress
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two IP addresses.
|
||||
* @return true in case inetAddress1 is greater than inetAddress2
|
||||
*/
|
||||
public static boolean greaterThan(InetAddress inetAddress1, InetAddress inetAddress2) {
|
||||
byte[] address1 = inetAddress1.getAddress();
|
||||
byte[] address2 = inetAddress2.getAddress();
|
||||
for (int i = 0; i < address1.length; i++) {
|
||||
if ((address1[i] & 0xFF) > (address2[i] & 0xFF))
|
||||
return true;
|
||||
else
|
||||
if ((address1[i] & 0xFF) < (address2[i] & 0xFF))
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments an IP address by 1.
|
||||
*/
|
||||
public static InetAddress increment(InetAddress address) {
|
||||
try {
|
||||
byte[] newAddress = address.getAddress();
|
||||
for (int i = newAddress.length-1; i >= 0; i--) {
|
||||
if (++newAddress[i] != 0x00)
|
||||
break;
|
||||
}
|
||||
return InetAddress.getByAddress(newAddress);
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
// this exception is unexpected here
|
||||
assert false : e;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the netmask string provided in special text format:
|
||||
* A.B.C.D, where each term is 0-255 or empty. If any term is empty, it is the same as 255.
|
||||
* @param netmaskString
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
public static InetAddress parseNetmask(String netmaskString) throws UnknownHostException {
|
||||
netmaskString = netmaskString.replaceAll("\\.\\.", ".255.");
|
||||
netmaskString = netmaskString.replaceAll("\\.\\.", ".255.");
|
||||
InetAddress netmask = InetAddress.getByName(netmaskString);
|
||||
return netmask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where mask bits are set, we use prototype bits.
|
||||
* Where mask bits are cleared, we leave bits as is.
|
||||
* @param addressBytes this array is modified according to the maskBytes and prototypeBytes
|
||||
* @param maskBytes
|
||||
* @param prototypeBytes
|
||||
*/
|
||||
public static void maskPrototypeAddressBytes(byte[] addressBytes, byte[] maskBytes, byte[] prototypeBytes) {
|
||||
for (int i = 0; i < addressBytes.length; i++) {
|
||||
addressBytes[i] = (byte) ((addressBytes[i] & ~maskBytes[i]) | (prototypeBytes[i] & maskBytes[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the passed address is likely either a broadcast or network address
|
||||
* @param address
|
||||
*/
|
||||
public static boolean isLikelyBroadcast(InetAddress address) {
|
||||
byte[] bytes = address.getAddress();
|
||||
return bytes[bytes.length-1] == 0 || bytes[bytes.length-1] == (byte)0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an IP address by hostname.
|
||||
* This method correctly resolves the local IP address on Linux.
|
||||
* @param hostname
|
||||
* @return IP address as String
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
public static String getAddressByName(String hostname) throws UnknownHostException {
|
||||
InetAddress address = InetAddress.getByName(hostname);
|
||||
if (address.isLoopbackAddress()) {
|
||||
// loopback address (127.0.0.1) was returned, try to find the local address
|
||||
// by enumeration of network interfaces
|
||||
try {
|
||||
outer:
|
||||
for (Enumeration i = NetworkInterface.getNetworkInterfaces(); i.hasMoreElements(); ) {
|
||||
NetworkInterface networkInterface = (NetworkInterface) i.nextElement();
|
||||
for (Enumeration i2 = networkInterface.getInetAddresses(); i2.hasMoreElements();) {
|
||||
InetAddress currentAddress = (InetAddress) i2.nextElement();
|
||||
if (!currentAddress.isLoopbackAddress()) {
|
||||
address = currentAddress;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SocketException e) {
|
||||
Logger.global.log(Level.FINE, "Cannot enumerate network interfaces", e);
|
||||
}
|
||||
}
|
||||
return address.getHostAddress();
|
||||
}
|
||||
|
||||
}
|
||||
54
ipscan/src/net/azib/ipscan/core/IntegerWithUnit.java
Executable file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
|
||||
/**
|
||||
* IntegerWithUnit - an Integer value together with a unit, e.g. "10 ms"
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class IntegerWithUnit implements Comparable {
|
||||
|
||||
private int value;
|
||||
private String unitLabel;
|
||||
|
||||
public IntegerWithUnit(int value, String unitLabel) {
|
||||
this.value = value;
|
||||
this.unitLabel = unitLabel;
|
||||
}
|
||||
|
||||
public int intValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return value + Labels.getLabel(unitLabel);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (obj instanceof IntegerWithUnit)
|
||||
return value == ((IntegerWithUnit) obj).value;
|
||||
return false;
|
||||
}
|
||||
|
||||
public int compareTo(Object obj) {
|
||||
if (this == obj)
|
||||
return 0;
|
||||
if (obj == null)
|
||||
return 1;
|
||||
int other = ((IntegerWithUnit) obj).value;
|
||||
return value == other ? 0 : value > other ? 1 : -1;
|
||||
}
|
||||
|
||||
}
|
||||
37
ipscan/src/net/azib/ipscan/core/NotAvailableValue.java
Executable file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
|
||||
/**
|
||||
* The value for displaying in the result list, meaning that the actual value is unknown,
|
||||
* because it wasn't resolved successfully.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class NotAvailableValue implements Comparable {
|
||||
|
||||
public static final NotAvailableValue INSTANCE = new NotAvailableValue();
|
||||
|
||||
private NotAvailableValue() {}
|
||||
|
||||
/**
|
||||
* Displays a user-friendly text string :-)
|
||||
*/
|
||||
public String toString() {
|
||||
// TODO: make this configurable
|
||||
return Labels.getLabel("fetcher.value.notAvailable");
|
||||
}
|
||||
|
||||
public int compareTo(Object obj) {
|
||||
if (this == obj)
|
||||
return 0;
|
||||
if (obj == null)
|
||||
return 1;
|
||||
// this value is smaller than any other object (except null)
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
37
ipscan/src/net/azib/ipscan/core/NotScannedValue.java
Executable file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
|
||||
/**
|
||||
* The value for displaying in the result list, meaning that the actual value is unknown,
|
||||
* because it was not scanned.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class NotScannedValue implements Comparable {
|
||||
|
||||
public static final NotScannedValue INSTANCE = new NotScannedValue();
|
||||
|
||||
private NotScannedValue() {}
|
||||
|
||||
/**
|
||||
* Displays a user-friendly text string :-)
|
||||
*/
|
||||
public String toString() {
|
||||
// TODO: make this configurable
|
||||
return Labels.getLabel("fetcher.value.notScanned");
|
||||
}
|
||||
|
||||
public int compareTo(Object obj) {
|
||||
if (this == obj)
|
||||
return 0;
|
||||
if (obj == null)
|
||||
return 1;
|
||||
// this value is smaller than any other object (except null)
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
87
ipscan/src/net/azib/ipscan/core/PortIterator.java
Executable file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
/**
|
||||
* A class for iteration of ports, specified in special format, like:
|
||||
* 1,5-7,35-40
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public final class PortIterator implements Cloneable {
|
||||
|
||||
private int[] portRangeStart;
|
||||
private int[] portRangeEnd;
|
||||
|
||||
private int rangeCountMinus1;
|
||||
private int rangeIndex;
|
||||
private int currentPort;
|
||||
|
||||
private boolean hasNext;
|
||||
|
||||
/**
|
||||
* Constructs the PortIterator instance
|
||||
* @param portString the port string to parse
|
||||
*/
|
||||
public PortIterator(String portString) {
|
||||
|
||||
if (portString != null && (portString = portString.trim()).length() > 0) {
|
||||
String[] portRanges = portString.split("[ \t\n\r,;]+");
|
||||
|
||||
// initialize storage
|
||||
portRangeStart = new int[portRanges.length+1]; // +1 for optimiation of 'next' method, prevents ArrayIndexOutOfBoundsException
|
||||
portRangeEnd = new int[portRanges.length];
|
||||
|
||||
// parse ints
|
||||
for (int i = 0; i < portRanges.length; i++) {
|
||||
String range = portRanges[i];
|
||||
int dashPos = range.indexOf('-') + 1;
|
||||
int endPort = Integer.parseInt(range.substring(dashPos));
|
||||
portRangeEnd[i] = endPort;
|
||||
portRangeStart[i] = dashPos == 0 ? endPort : Integer.parseInt(range.substring(0, dashPos-1));
|
||||
}
|
||||
|
||||
currentPort = portRangeStart[0];
|
||||
rangeCountMinus1 = portRanges.length - 1;
|
||||
hasNext = rangeCountMinus1 >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if there are more ports left
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return hasNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return next port number
|
||||
*/
|
||||
public int next() {
|
||||
int returnPort = currentPort++;
|
||||
|
||||
if (currentPort > portRangeEnd[rangeIndex]) {
|
||||
hasNext = rangeIndex < rangeCountMinus1;
|
||||
rangeIndex++;
|
||||
currentPort = portRangeStart[rangeIndex];
|
||||
}
|
||||
|
||||
return returnPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the PortIterator instance.
|
||||
* @return a shallow copy
|
||||
*/
|
||||
public PortIterator copy() {
|
||||
try {
|
||||
return (PortIterator) super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
assert false : "this should never happen";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
72
ipscan/src/net/azib/ipscan/core/Scanner.java
Executable file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.azib.ipscan.fetchers.Fetcher;
|
||||
import net.azib.ipscan.fetchers.FetcherRegistry;
|
||||
|
||||
/**
|
||||
* Scanner functionality is encapsulated in this class.
|
||||
* It uses a list of fetchers to perform the actual scanning.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class Scanner {
|
||||
|
||||
private FetcherRegistry fetcherRegistry;
|
||||
|
||||
public Scanner(FetcherRegistry fetcherRegistry) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all registered fetchers for the current IP address.
|
||||
* @param address the IP address to scan
|
||||
* @param result where the results are injected
|
||||
*/
|
||||
public void scan(InetAddress address, ScanningResult result) {
|
||||
|
||||
// create a scanning subject object, which will be used by fetchers
|
||||
// to cache common information
|
||||
ScanningSubject scanningSubject = new ScanningSubject(address);
|
||||
|
||||
// populate results
|
||||
int fetcherIndex = 0;
|
||||
for (Iterator i = fetcherRegistry.getSelectedFetchers().iterator(); i.hasNext();) {
|
||||
Fetcher fetcher = (Fetcher) i.next();
|
||||
if (!scanningSubject.isScanningAborted()) {
|
||||
Object value = fetcher.scan(scanningSubject);
|
||||
result.setValue(fetcherIndex, value != null ? value : NotAvailableValue.INSTANCE);
|
||||
}
|
||||
else {
|
||||
result.setValue(fetcherIndex, NotScannedValue.INSTANCE);
|
||||
}
|
||||
fetcherIndex++;
|
||||
}
|
||||
|
||||
result.setType(scanningSubject.getResultType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Init everything needed for scanning, including Fetchers
|
||||
*/
|
||||
public void init() {
|
||||
for (Iterator i = fetcherRegistry.getSelectedFetchers().iterator(); i.hasNext();) {
|
||||
((Fetcher)i.next()).init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup after a scan
|
||||
*/
|
||||
public void cleanup() {
|
||||
for (Iterator i = fetcherRegistry.getSelectedFetchers().iterator(); i.hasNext();) {
|
||||
((Fetcher)i.next()).cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
148
ipscan/src/net/azib/ipscan/core/ScannerThread.java
Executable file
@ -0,0 +1,148 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import net.azib.ipscan.config.Config;
|
||||
import net.azib.ipscan.feeders.Feeder;
|
||||
|
||||
/**
|
||||
* Scanning thread.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ScannerThread extends Thread {
|
||||
|
||||
private Scanner scanner;
|
||||
private ScanningResultList scanningResultList;
|
||||
private Feeder feeder;
|
||||
private ScanningStateCallback statusCallback;
|
||||
private ScanningResultsCallback resultsCallback;
|
||||
private int state;
|
||||
private int runningThreads;
|
||||
private int maxThreads = Config.getGlobal().maxThreads;
|
||||
private int threadDelay = Config.getGlobal().threadDelay;
|
||||
|
||||
public ScannerThread(Feeder feeder, Scanner scanner, ScanningResultList scanningResults) {
|
||||
super("Scanner Thread");
|
||||
// this thread is daemon because we want JVM to terminate it
|
||||
// automatically if user closes the program (Main thread, that is)
|
||||
setDaemon(true);
|
||||
this.feeder = feeder;
|
||||
this.scanner = scanner;
|
||||
this.scanningResultList = scanningResults;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
changeStatus(ScanningStateCallback.STATE_SCANNING);
|
||||
|
||||
scanner.init();
|
||||
|
||||
while(feeder.hasNext() && state == ScanningStateCallback.STATE_SCANNING) {
|
||||
try {
|
||||
|
||||
// make a small delay between thread creation
|
||||
Thread.sleep(threadDelay);
|
||||
|
||||
if (runningThreads >= maxThreads) {
|
||||
// skip this iteration until more threads can be created
|
||||
continue;
|
||||
}
|
||||
|
||||
// rerieve the next IP address to scan
|
||||
final InetAddress address = feeder.next();
|
||||
|
||||
// check if this is a likely broadcast address and needs to be skipped
|
||||
if (Config.getGlobal().skipBroadcastAddresses && InetAddressUtils.isLikelyBroadcast(address)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// now increment the number of active threads, because we are going
|
||||
// to start a new one below
|
||||
runningThreads++;
|
||||
|
||||
// prepare results receiver for upcoming results
|
||||
int preparationNumber = resultsCallback.prepareForResults(address);
|
||||
|
||||
// notify listeners of the progress we are doing
|
||||
statusCallback.updateProgress(address, runningThreads, feeder.getPercentageComplete());
|
||||
|
||||
// scan each IP in parallel, in a separate thread
|
||||
new IPThread(address, preparationNumber).start();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// inform that no more addresses left
|
||||
changeStatus(ScanningStateCallback.STATE_STOPPING);
|
||||
|
||||
// now wait for all threads, which are still running
|
||||
try {
|
||||
// TODO: make a better and safer implementation
|
||||
while (runningThreads > 0) {
|
||||
Thread.sleep(200);
|
||||
statusCallback.updateProgress(null, runningThreads, 100);
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// nothing special to do here
|
||||
}
|
||||
|
||||
scanner.cleanup();
|
||||
|
||||
// finally, the scanning is complete
|
||||
changeStatus(ScanningStateCallback.STATE_IDLE);
|
||||
}
|
||||
|
||||
private void changeStatus(int status) {
|
||||
this.state = status;
|
||||
statusCallback.scannerStateChanged(status);
|
||||
}
|
||||
|
||||
public void forceStop() {
|
||||
changeStatus(ScanningStateCallback.STATE_STOPPING);
|
||||
}
|
||||
|
||||
public void abort() {
|
||||
changeStatus(ScanningStateCallback.STATE_KILLING);
|
||||
}
|
||||
|
||||
public void setResultsCallback(ScanningResultsCallback resultsCallback) {
|
||||
this.resultsCallback = resultsCallback;
|
||||
}
|
||||
|
||||
public void setStatusCallback(ScanningStateCallback statusCallback) {
|
||||
this.statusCallback = statusCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* This thread gets executed for each scanned IP address to do the actual
|
||||
* scanning.
|
||||
*/
|
||||
private class IPThread extends Thread {
|
||||
private InetAddress address;
|
||||
private int preparationIndex;
|
||||
|
||||
IPThread(InetAddress address, int preparationIndex) {
|
||||
super("IP Thread: " + address.getHostAddress());
|
||||
setDaemon(true);
|
||||
this.address = address;
|
||||
this.preparationIndex = preparationIndex;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
ScanningResult result = scanningResultList.getResult(preparationIndex);
|
||||
scanner.scan(address, result);
|
||||
resultsCallback.consumeResults(preparationIndex, result);
|
||||
}
|
||||
finally {
|
||||
runningThreads--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
ipscan/src/net/azib/ipscan/core/ScannerThreadFactory.java
Executable file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import net.azib.ipscan.feeders.Feeder;
|
||||
|
||||
/**
|
||||
* ScannerThreadFactory
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ScannerThreadFactory {
|
||||
|
||||
private ScanningResultList scanningResults;
|
||||
private Scanner scanner;
|
||||
|
||||
public ScannerThreadFactory(ScanningResultList scanningResults, Scanner scanner) {
|
||||
this.scanningResults = scanningResults;
|
||||
this.scanner = scanner;
|
||||
}
|
||||
|
||||
public ScannerThread createScannerThread(Feeder feeder) {
|
||||
return new ScannerThread(feeder, scanner, scanningResults);
|
||||
}
|
||||
|
||||
}
|
||||
71
ipscan/src/net/azib/ipscan/core/ScanningResult.java
Executable file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The holder of scanning result for a single IP address.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ScanningResult {
|
||||
|
||||
/** The scanned IP address */
|
||||
private InetAddress address;
|
||||
/** Scanning results, result of each Fetcher is an element */
|
||||
private Object[] values;
|
||||
/** Scanning result type, see constants in {@link ScanningSubject} */
|
||||
private int type;
|
||||
|
||||
/**
|
||||
* Creates a new instance, initializing the first value to the
|
||||
* provided address
|
||||
* @param address
|
||||
* @param numberOfFetchers the number of currently available fetchers
|
||||
*/
|
||||
ScanningResult(InetAddress address, int numberOfFetchers) {
|
||||
this.address = address;
|
||||
values = new Object[numberOfFetchers];
|
||||
values[0] = address.getHostAddress();
|
||||
type = ScanningSubject.RESULT_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
public InetAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scanning results as an unmodifiable List, result of each Fetcher is an element
|
||||
*/
|
||||
public List getValues() {
|
||||
return Arrays.asList(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets scanning result type, see constants in {@link ScanningSubject}
|
||||
*/
|
||||
void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scanning result type, see constants in {@link ScanningSubject}
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value returned by the specified fetcher
|
||||
* @param fetcherIndex
|
||||
* @param value
|
||||
*/
|
||||
public void setValue(int fetcherIndex, Object value) {
|
||||
values[fetcherIndex] = value;
|
||||
}
|
||||
|
||||
}
|
||||
153
ipscan/src/net/azib/ipscan/core/ScanningResultList.java
Executable file
@ -0,0 +1,153 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.fetchers.Fetcher;
|
||||
import net.azib.ipscan.fetchers.FetcherRegistry;
|
||||
|
||||
/**
|
||||
* The holder of scanning results.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ScanningResultList {
|
||||
|
||||
private static final int RESULT_LIST_INITIAL_SIZE = 1024;
|
||||
|
||||
private FetcherRegistry fetcherRegistry;
|
||||
// selected fetchers are cached here, because the may be changed in the registry already
|
||||
private List selectedFetchers;
|
||||
|
||||
private List resultList = new ArrayList(1024);
|
||||
private ResultsComparator resultsComparator = new ResultsComparator();
|
||||
|
||||
public ScanningResultList(FetcherRegistry fetcherRegistry) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return selected fetchers that were used for the last scan
|
||||
* Note: they may be different from {@link FetcherRegistry#getSelectedFetchers()}
|
||||
*/
|
||||
public List getFetchers() {
|
||||
return selectedFetchers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the new scanned IP address
|
||||
* @param address
|
||||
* @return the index of the added address, can be used in calls to other methods
|
||||
*/
|
||||
public synchronized int add(InetAddress address) {
|
||||
int index = resultList.size();
|
||||
resultList.add(new ScanningResult(address, fetcherRegistry.getSelectedFetchers().size()));
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all results for a particular IP address as a String.
|
||||
* This is used in showing the IP Details dialog box.
|
||||
* TODO: write tests!
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public synchronized String getResultsAsString(int index) {
|
||||
// cross-platform newline :-)
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
ScanningResult scanningResult = (ScanningResult) resultList.get(index);
|
||||
StringBuffer details = new StringBuffer(1024);
|
||||
Iterator iterator = scanningResult.getValues().iterator();
|
||||
for (int i = 0; iterator.hasNext(); i++) {
|
||||
String fetcherName = Labels.getLabel(((Fetcher)selectedFetchers.get(i)).getLabel());
|
||||
details.append(fetcherName).append(":\t");
|
||||
Object value = iterator.next();
|
||||
details.append(value != null ? value : "");
|
||||
details.append(newLine).append("--------------------------------------------------------------------------------------").append(newLine);
|
||||
}
|
||||
return details.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears previous scanning results, prepares for a new scan.
|
||||
*/
|
||||
public synchronized void clear() {
|
||||
// clear the results
|
||||
resultList.clear();
|
||||
// reload currently selected fetchers
|
||||
selectedFetchers = new ArrayList(fetcherRegistry.getSelectedFetchers());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an Iterator of scanning results
|
||||
*
|
||||
* Note: the returned Iterator is not synchronized
|
||||
*/
|
||||
public synchronized Iterator iterator() {
|
||||
return resultList.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return the results of the IP adress, corresponding to an index
|
||||
*/
|
||||
public synchronized ScanningResult getResult(int index) {
|
||||
return (ScanningResult) resultList.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the elements by the provided indices
|
||||
* Note: old indices returned by {@link #add(InetAddress)} are no longer valid
|
||||
* @param indices a sorted list of indices to remove
|
||||
*/
|
||||
public synchronized void remove(int[] indices) {
|
||||
// this rebuild is faster then a number of calls to remove()
|
||||
// however, a further speedup can be obtained by using a Set instead of binarySearch()
|
||||
List newList = new ArrayList(RESULT_LIST_INITIAL_SIZE);
|
||||
for (int i = 0; i < resultList.size(); i++) {
|
||||
if (Arrays.binarySearch(indices, i) < 0)
|
||||
newList.add(resultList.get(i));
|
||||
}
|
||||
resultList = newList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts by the specified column index.
|
||||
* Note: old indices returned by {@link #add(InetAddress)} are no longer valid
|
||||
* @param columnIndex
|
||||
*/
|
||||
public synchronized void sort(int columnIndex) {
|
||||
resultsComparator.index = columnIndex;
|
||||
Collections.sort(resultList, resultsComparator);
|
||||
}
|
||||
|
||||
private static class ResultsComparator implements Comparator {
|
||||
|
||||
private int index;
|
||||
|
||||
public int compare(Object o1, Object o2) {
|
||||
if (!(o1 instanceof ScanningResult))
|
||||
return -1;
|
||||
if (!(o2 instanceof ScanningResult))
|
||||
return 1;
|
||||
|
||||
Object val1 = ((ScanningResult)o1).getValues().get(index);
|
||||
Object val2 = ((ScanningResult)o2).getValues().get(index);
|
||||
|
||||
return val1.toString().compareTo(val2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
30
ipscan/src/net/azib/ipscan/core/ScanningResultsCallback.java
Executable file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* This callback is called to consume scanning results.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public interface ScanningResultsCallback {
|
||||
|
||||
/**
|
||||
* This method is called just before starting to retrieve
|
||||
* scanning results for the specified address.
|
||||
* @param address
|
||||
* @return the method should return an int
|
||||
*/
|
||||
public int prepareForResults(InetAddress address);
|
||||
|
||||
/**
|
||||
* This method is called when scanning results are ready.
|
||||
* @param preparationNumber the number, which was previously returned by prepareForResults().
|
||||
* @param results the List of Strings, each String corresponds to a Fetcher
|
||||
*/
|
||||
public void consumeResults(int preparationNumber, ScanningResult results);
|
||||
|
||||
}
|
||||
40
ipscan/src/net/azib/ipscan/core/ScanningStateCallback.java
Executable file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* This callback is called on scanning status updates.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public interface ScanningStateCallback {
|
||||
|
||||
public static final int STATE_IDLE = 0;
|
||||
public static final int STATE_SCANNING = 1;
|
||||
public static final int STATE_STOPPING = 2;
|
||||
public static final int STATE_KILLING = 3;
|
||||
|
||||
/**
|
||||
* This method is called on scanner status changes,
|
||||
* eg. when scanning is about to stop.
|
||||
*
|
||||
* @param status integer value of current status, having the
|
||||
* corresponding STATE_XXX constant
|
||||
*/
|
||||
public void scannerStateChanged(int status);
|
||||
|
||||
/**
|
||||
* This method is called on scanning progress updates.
|
||||
* There are no guarantees that this method is called on every
|
||||
* scanning iteration.
|
||||
*
|
||||
* @param currentAddress currently scanned IP address, can be null
|
||||
* @param runningThreads number of currently running threads
|
||||
* @param percentageComplete value from 0 to 100, showing how much work
|
||||
* is already done.
|
||||
*/
|
||||
public void updateProgress(InetAddress currentAddress, int runningThreads, int percentageComplete);
|
||||
}
|
||||
100
ipscan/src/net/azib/ipscan/core/ScanningSubject.java
Executable file
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* This file is a part of Angry IP Scanner source code,
|
||||
* see http://www.azib.net/ for more information.
|
||||
*/
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Scanning subject represents a single scanned
|
||||
* IP address and any additional arbitrary parameters,
|
||||
* which may be used to cache some intermediate data
|
||||
* among different Fetchers.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ScanningSubject {
|
||||
|
||||
// constants for result type (they can be modified by some Fetchers)
|
||||
public static final int RESULT_TYPE_UNKNOWN = 0;
|
||||
public static final int RESULT_TYPE_DEAD = 1;
|
||||
public static final int RESULT_TYPE_ALIVE = 2;
|
||||
public static final int RESULT_TYPE_ADDITIONAL_INFO = 3;
|
||||
|
||||
/** The address being scanned */
|
||||
private InetAddress address;
|
||||
/** Arbitrary parameters for sharing among different (but related) Fetchers */
|
||||
private Map parameters;
|
||||
/** The result type constant value, can be modified by some Fetchers */
|
||||
private int resultType = RESULT_TYPE_UNKNOWN;
|
||||
/** Whether we need to continue scanning or it can be aborted */
|
||||
private boolean isScanningAborted = false;
|
||||
|
||||
/**
|
||||
* This constructor should only be used by the Scanner class or unit tests.
|
||||
*/
|
||||
public ScanningSubject(InetAddress address) {
|
||||
this.address = address;
|
||||
this.parameters = new HashMap();
|
||||
}
|
||||
|
||||
public InetAddress getIPAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a subject specific named parameter.
|
||||
*/
|
||||
public void setParameter(String name, Object value) {
|
||||
parameters.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a subject specific named parameter,
|
||||
* previosly set by setParameter().
|
||||
*/
|
||||
public Object getParameter(String name) {
|
||||
return parameters.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true in case parameter with given name was specified.
|
||||
* This method is useful in case parameter value was null.
|
||||
*/
|
||||
public boolean hasParameter(String name) {
|
||||
return parameters.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the result type constant value, possibly modified by Fetchers
|
||||
*/
|
||||
public int getResultType() {
|
||||
return resultType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an ability for Fetchers to determine the result type of scanning this particular address
|
||||
* @param resultType constant value
|
||||
*/
|
||||
public void setResultType(int resultType) {
|
||||
this.resultType = resultType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a fetcher has instructed to abort scanning
|
||||
*/
|
||||
public boolean isScanningAborted() {
|
||||
return isScanningAborted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to inform the scanner to abort scanning
|
||||
*/
|
||||
public void abortScanning() {
|
||||
this.isScanningAborted = true;
|
||||
}
|
||||
|
||||
}
|
||||
139
ipscan/src/net/azib/ipscan/core/net/ICMPPinger.java
Normal file
@ -0,0 +1,139 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.savarese.rocksaw.net.RawSocket;
|
||||
import org.savarese.vserv.tcpip.ICMPEchoPacket;
|
||||
import org.savarese.vserv.tcpip.ICMPPacket;
|
||||
import org.savarese.vserv.tcpip.IPPacket;
|
||||
import org.savarese.vserv.tcpip.OctetConverter;
|
||||
|
||||
/**
|
||||
* Pinging code is encapsulated here.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ICMPPinger implements Pinger {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ICMPPinger.class.getName());
|
||||
|
||||
private int timeout;
|
||||
|
||||
public ICMPPinger(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
private RawSocket createRawSocket() throws IOException {
|
||||
RawSocket socket = new RawSocket();
|
||||
socket.open(RawSocket.PF_INET, IPPacket.PROTOCOL_ICMP);
|
||||
|
||||
try {
|
||||
socket.setSendTimeout(timeout);
|
||||
socket.setReceiveTimeout(timeout);
|
||||
} catch (java.net.SocketException se) {
|
||||
socket.setUseSelectTimeout(true);
|
||||
socket.setSendTimeout(timeout);
|
||||
socket.setReceiveTimeout(timeout);
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
private void sendReceiveEchoPacket(RawSocket socket, InetAddress address, int sequence, PingResult result) throws IOException {
|
||||
|
||||
ICMPEchoPacket packet = new ICMPEchoPacket(1);
|
||||
byte[] data = new byte[84];
|
||||
packet.setData(data);
|
||||
packet.setIPHeaderLength(5);
|
||||
packet.setICMPDataByteLength(56);
|
||||
packet.setType(ICMPPacket.TYPE_ECHO_REQUEST);
|
||||
packet.setCode(0);
|
||||
packet.setIdentifier(hashCode() & 0xFFFF); // some identification stuff
|
||||
packet.setSequenceNumber(sequence);
|
||||
|
||||
int offset = packet.getIPHeaderByteLength();
|
||||
int dataOffset = offset + packet.getICMPHeaderByteLength();
|
||||
int length = packet.getICMPPacketByteLength();
|
||||
|
||||
OctetConverter.longToOctets(System.currentTimeMillis(), data, dataOffset);
|
||||
packet.computeICMPChecksum();
|
||||
|
||||
socket.write(address, data, offset, length);
|
||||
|
||||
try {
|
||||
int skippedCount = 0;
|
||||
do {
|
||||
socket.read(address, data);
|
||||
skippedCount++;
|
||||
//if (packet.getType() == ICMPPacket.TYPE_ECHO_REPLY)
|
||||
// System.err.println(Thread.currentThread() + " " + packet.getSourceAsInetAddress().getHostAddress() + ": " + skippedCount);
|
||||
}
|
||||
while (packet.getType() != ICMPPacket.TYPE_ECHO_REPLY ||
|
||||
packet.getIdentifier() != (hashCode() & 0xFFFF) ||
|
||||
packet.getSequenceNumber() != sequence);
|
||||
|
||||
if (packet.getSourceAsInetAddress().equals(address)) {
|
||||
long end = System.currentTimeMillis();
|
||||
long start = OctetConverter.octetsToLong(data, dataOffset);
|
||||
long time = end - start;
|
||||
|
||||
result.totalTime += time;
|
||||
result.replyCount++;
|
||||
result.ttl = packet.getTTL() & 0xFF;
|
||||
}
|
||||
}
|
||||
catch (InterruptedIOException e) {
|
||||
// socket read timeout
|
||||
LOG.finer("Receive timeout");
|
||||
// TODO: make RawSocket to throw Exceptions without the stack trace (for speed)
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
LOG.log(Level.WARNING, "Cannot retrieve the source address of an ICMP packet", e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.log(Level.WARNING, "Unable to read from the socket", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues the specified number of pings and
|
||||
* waits for replies.
|
||||
*
|
||||
* @param address address to ping
|
||||
* @param count number of pings to perform
|
||||
*/
|
||||
public PingResult ping(InetAddress address, int count) throws IOException {
|
||||
|
||||
PingResult result = new PingResult(address);
|
||||
RawSocket socket = createRawSocket();
|
||||
|
||||
try {
|
||||
// send a bunch of packets
|
||||
for (int i = 0; i < count; i++) {
|
||||
try {
|
||||
sendReceiveEchoPacket(socket, address, i, result);
|
||||
}
|
||||
catch (InterruptedIOException e) {
|
||||
// ignore timeouts
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
socket.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
}
|
||||
240
ipscan/src/net/azib/ipscan/core/net/ICMPSharedPinger.java
Executable file
@ -0,0 +1,240 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.savarese.rocksaw.net.RawSocket;
|
||||
import org.savarese.vserv.tcpip.ICMPEchoPacket;
|
||||
import org.savarese.vserv.tcpip.ICMPPacket;
|
||||
import org.savarese.vserv.tcpip.IPPacket;
|
||||
import org.savarese.vserv.tcpip.OctetConverter;
|
||||
|
||||
/**
|
||||
* Shared multithreaded pinger.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ICMPSharedPinger implements Pinger {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ICMPSharedPinger.class.getName());
|
||||
|
||||
/** a single raw socket for sending of all ICMP packets */
|
||||
private RawSocket sendingSocket;
|
||||
/** a single raw socket for receiving of all ICMP packets */
|
||||
private RawSocket receivingSocket;
|
||||
/** the map with PingResults, keys are InetAddress */
|
||||
private Map results = Collections.synchronizedMap(new HashMap());
|
||||
|
||||
private Thread receiverThread;
|
||||
|
||||
private int timeout;
|
||||
private int timeOffsetInPacket;
|
||||
|
||||
public ICMPSharedPinger(int timeout) throws IOException {
|
||||
// we use two shared sockets, because it works more efficiently
|
||||
// OSs tend to copy all received ICMP packets to all open raw sockets,
|
||||
// so it is very bad to have a separate raw socket for each scanning thread
|
||||
sendingSocket = new RawSocket();
|
||||
sendingSocket.open(RawSocket.PF_INET, IPPacket.PROTOCOL_ICMP);
|
||||
receivingSocket = new RawSocket();
|
||||
receivingSocket.open(RawSocket.PF_INET, IPPacket.PROTOCOL_ICMP);
|
||||
this.timeout = timeout;
|
||||
|
||||
try {
|
||||
sendingSocket.setSendTimeout(timeout);
|
||||
receivingSocket.setReceiveTimeout(timeout);
|
||||
//receivingSocket.setReceiveBufferSize()
|
||||
}
|
||||
catch (java.net.SocketException se) {
|
||||
sendingSocket.setUseSelectTimeout(true);
|
||||
receivingSocket.setUseSelectTimeout(true);
|
||||
sendingSocket.setSendTimeout(timeout);
|
||||
receivingSocket.setReceiveTimeout(timeout);
|
||||
}
|
||||
|
||||
receiverThread = new PacketReceiverThread();
|
||||
receiverThread.start();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
synchronized (sendingSocket) {
|
||||
sendingSocket.close();
|
||||
}
|
||||
receiverThread.interrupt();
|
||||
}
|
||||
|
||||
public PingResult ping(InetAddress address, int count) throws IOException {
|
||||
|
||||
PingResult result = new PingResult(address);
|
||||
results.put(address, result);
|
||||
|
||||
// TODO: make ICMPEchoPacket accept byte array in the constructor
|
||||
ICMPEchoPacket packet = new ICMPEchoPacket(1);
|
||||
byte[] data = new byte[84];
|
||||
packet.setData(data);
|
||||
packet.setIPHeaderLength(5);
|
||||
packet.setICMPDataByteLength(56);
|
||||
packet.setType(ICMPPacket.TYPE_ECHO_REQUEST);
|
||||
packet.setCode(0);
|
||||
packet.setIdentifier(hashCode() & 0xFFFF); // some identification stuff
|
||||
|
||||
try {
|
||||
// send a bunch of packets
|
||||
// note: we send sequence numbers starting from 1 (this is used by the ReceiverThread)
|
||||
for (int i = 1; i <= count; i++) {
|
||||
packet.setSequenceNumber(i);
|
||||
|
||||
int offset = packet.getIPHeaderByteLength();
|
||||
timeOffsetInPacket = offset + packet.getICMPHeaderByteLength();
|
||||
int length = packet.getICMPPacketByteLength();
|
||||
|
||||
OctetConverter.longToOctets(System.currentTimeMillis(), data, timeOffsetInPacket);
|
||||
packet.computeICMPChecksum();
|
||||
|
||||
if (LOG.isLoggable(Level.FINEST)) {
|
||||
LOG.finest("Pinging " + i + result.address);
|
||||
}
|
||||
synchronized (sendingSocket) {
|
||||
sendingSocket.write(result.address, data, offset, length);
|
||||
}
|
||||
|
||||
try {
|
||||
// a small pause between sending the packets
|
||||
Thread.sleep(15);
|
||||
}
|
||||
catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
int totalTimeout = timeout * count;
|
||||
while (totalTimeout > 0 && result.replyCount < count) {
|
||||
if (LOG.isLoggable(Level.FINEST)) {
|
||||
LOG.finest("Waiting for response " + address + ": " + totalTimeout);
|
||||
}
|
||||
synchronized (result) {
|
||||
// wait until we have an answer
|
||||
try {
|
||||
result.wait(timeout);
|
||||
}
|
||||
catch (InterruptedException e) {}
|
||||
}
|
||||
totalTimeout -= timeout;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
// remove garbage
|
||||
results.remove(address);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An internal thread for receiving of packets
|
||||
*/
|
||||
private class PacketReceiverThread extends Thread {
|
||||
|
||||
public PacketReceiverThread() {
|
||||
super("Ping packet receiver");
|
||||
setDaemon(true);
|
||||
setPriority(Thread.MAX_PRIORITY);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
ICMPEchoPacket packet = new ICMPEchoPacket(1);
|
||||
byte[] data = new byte[84];
|
||||
packet.setData(data);
|
||||
packet.setIPHeaderLength(5);
|
||||
packet.setICMPDataByteLength(56);
|
||||
|
||||
// we use this address for receiving
|
||||
// due to some reason, raw sockets return packets coming from any addresses anyway
|
||||
InetAddress tmpAddress = null;
|
||||
try {
|
||||
tmpAddress = InetAddress.getLocalHost();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
LOG.log(Level.SEVERE, null, e);
|
||||
}
|
||||
|
||||
try {
|
||||
// Windows OS cannot read from a raw socket before anything has been sent through it
|
||||
receivingSocket.write(tmpAddress, data);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.log(Level.WARNING, "Sending of test packet failed", e);
|
||||
}
|
||||
|
||||
do {
|
||||
try {
|
||||
receivingSocket.read(tmpAddress, data);
|
||||
|
||||
if (packet.getType() == ICMPPacket.TYPE_ECHO_REPLY &&
|
||||
packet.getIdentifier() == (ICMPSharedPinger.this.hashCode() & 0xFFFF) &&
|
||||
packet.getSequenceNumber() > 0) {
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
||||
PingResult result = (PingResult) results.get(packet.getSourceAsInetAddress());
|
||||
if (result == null) {
|
||||
LOG.warning("ICMP packet received from an unknown address: " + packet.getSourceAsInetAddress());
|
||||
continue;
|
||||
}
|
||||
|
||||
long startTime = OctetConverter.octetsToLong(data, timeOffsetInPacket);
|
||||
long time = endTime - startTime;
|
||||
|
||||
if (LOG.isLoggable(Level.FINEST)) {
|
||||
LOG.finest("Received " + packet.getSequenceNumber() + packet.getSourceAsInetAddress() + ": " + time);
|
||||
}
|
||||
|
||||
result.totalTime += time;
|
||||
result.replyCount++;
|
||||
// TTL should be the same among all packets
|
||||
result.ttl = packet.getTTL() & 0xFF;
|
||||
|
||||
synchronized (result) {
|
||||
// notify the sender that we have an answer :-)
|
||||
result.notifyAll();
|
||||
}
|
||||
}
|
||||
else
|
||||
if (packet.getType() == ICMPPacket.TYPE_HOST_UNREACHABLE) {
|
||||
// TODO: received non-ECHO_REPLY packets may also be useful, saying "destination is unreachable"
|
||||
// packet body in this case is the sent ICMP_REQUEST packet
|
||||
}
|
||||
}
|
||||
catch (InterruptedIOException e) {
|
||||
// socket read timeout
|
||||
LOG.finer("Receive timeout");
|
||||
// TODO: make RawSocket to throw Exceptions without the stack trace (for speed)
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
LOG.log(Level.WARNING, "Cannot retrieve the source address of an ICMP packet", e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.log(Level.WARNING, "Unable to read from the socket", e);
|
||||
}
|
||||
|
||||
}
|
||||
while(!interrupted());
|
||||
|
||||
try {
|
||||
receivingSocket.close();
|
||||
}
|
||||
catch (IOException e) { }
|
||||
LOG.fine("Terminated");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
41
ipscan/src/net/azib/ipscan/core/net/PingResult.java
Executable file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core.net;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* The result of pinging
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class PingResult {
|
||||
|
||||
InetAddress address;
|
||||
|
||||
int ttl;
|
||||
long totalTime;
|
||||
int replyCount;
|
||||
|
||||
public PingResult(InetAddress address) {
|
||||
this.address = address;
|
||||
|
||||
}
|
||||
|
||||
public int getTTL() {
|
||||
return ttl;
|
||||
}
|
||||
|
||||
public int getAverageTime() {
|
||||
return (int)(totalTime / replyCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true in case at least one reply was received
|
||||
*/
|
||||
public boolean isAlive() {
|
||||
return replyCount > 0;
|
||||
}
|
||||
|
||||
}
|
||||
30
ipscan/src/net/azib/ipscan/core/net/Pinger.java
Executable file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* Pinger
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public interface Pinger {
|
||||
|
||||
/**
|
||||
* Closes the raw socket opened by the constructor. After calling this
|
||||
* method, the object cannot be used.
|
||||
*/
|
||||
public void close() throws IOException;
|
||||
|
||||
/**
|
||||
* Issues the specified number of pings and
|
||||
* waits for replies.
|
||||
*
|
||||
* @param count number of pings to perform
|
||||
*/
|
||||
public PingResult ping(InetAddress address, int count) throws IOException;
|
||||
|
||||
}
|
||||
25
ipscan/src/net/azib/ipscan/core/net/PingerRegistry.java
Executable file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core.net;
|
||||
|
||||
/**
|
||||
* PingerRegistry
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public interface PingerRegistry {
|
||||
|
||||
/**
|
||||
* @return a String array of pinger names (labels)
|
||||
*/
|
||||
public String[] getRegisteredNames();
|
||||
|
||||
/**
|
||||
* Creates a new instance of currently selected Pinger
|
||||
* @param timeout
|
||||
* @return the instance
|
||||
*/
|
||||
public Pinger createPinger(String pingerName, int timeout);
|
||||
|
||||
}
|
||||
58
ipscan/src/net/azib/ipscan/core/net/PingerRegistryImpl.java
Executable file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core.net;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* PingerRegistryImpl
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class PingerRegistryImpl implements PingerRegistry {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PingerRegistryImpl.class.getName());
|
||||
|
||||
/** All available Pinger implementations */
|
||||
private Map pingers;
|
||||
|
||||
public PingerRegistryImpl() {
|
||||
pingers = new LinkedHashMap();
|
||||
pingers.put("pinger.icmp", ICMPSharedPinger.class);
|
||||
pingers.put("pinger.icmp2", ICMPPinger.class);
|
||||
pingers.put("pinger.udp", UDPPinger.class);
|
||||
pingers.put("pinger.tcp", TCPPinger.class);
|
||||
|
||||
// TODO: implement a windows-specific ICMP pinger for XP SP2 and beyond that uses ping.dll
|
||||
// TODO: autodetect working pingers here
|
||||
}
|
||||
|
||||
public String[] getRegisteredNames() {
|
||||
return (String[]) pingers.keySet().toArray(new String[pingers.size()]);
|
||||
}
|
||||
|
||||
public Pinger createPinger(String pingerName, int timeout) {
|
||||
Class pingerClass = (Class) pingers.get(pingerName);
|
||||
Constructor constructor;
|
||||
try {
|
||||
constructor = pingerClass.getConstructor(new Class[] {int.class});
|
||||
return (Pinger) constructor.newInstance(new Object[] {new Integer(timeout)});
|
||||
}
|
||||
catch (Exception e) {
|
||||
Throwable t = e instanceof InvocationTargetException ? e.getCause() : e;
|
||||
String message = "Unable to create pinger: " + pingerName;
|
||||
LOG.log(Level.SEVERE, message, t);
|
||||
if (t instanceof RuntimeException)
|
||||
throw (RuntimeException) t;
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
71
ipscan/src/net/azib/ipscan/core/net/TCPPinger.java
Executable file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* TCP Pinger. Uses a TCP port to ping, doesn't require root privileges.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class TCPPinger implements Pinger {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(UDPPinger.class.getName());
|
||||
|
||||
private static final int PROBE_TCP_PORT = 80;
|
||||
|
||||
private int timeout;
|
||||
|
||||
public TCPPinger(int timeout) {
|
||||
// use double timeout, because TCP connect() produces more packets
|
||||
this.timeout = timeout * 2;
|
||||
}
|
||||
|
||||
public PingResult ping(InetAddress address, int count) throws IOException {
|
||||
PingResult result = new PingResult(address);
|
||||
|
||||
Socket socket = new Socket();
|
||||
socket.setSoTimeout(timeout);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
socket.connect(new InetSocketAddress(address, PROBE_TCP_PORT), timeout);
|
||||
result.replyCount++;
|
||||
result.totalTime+=System.currentTimeMillis()-startTime;
|
||||
}
|
||||
catch (ConnectException e) {
|
||||
result.replyCount++;
|
||||
result.totalTime+=System.currentTimeMillis()-startTime;
|
||||
}
|
||||
catch (SocketTimeoutException e) {
|
||||
}
|
||||
catch (NoRouteToHostException e) {
|
||||
// TODO: this means that the host is down
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.setLevel(Level.ALL);
|
||||
LOG.log(Level.FINER, null, e);
|
||||
}
|
||||
|
||||
try {
|
||||
socket.close();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
// nothing to do here
|
||||
}
|
||||
}
|
||||
65
ipscan/src/net/azib/ipscan/core/net/UDPPinger.java
Executable file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.core.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.PortUnreachableException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* UDP Pinger. Uses an UDP port to ping, doesn't require root privileges.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class UDPPinger implements Pinger {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(UDPPinger.class.getName());
|
||||
|
||||
private static final int PROBE_UDP_PORT = 33381;
|
||||
|
||||
private int timeout;
|
||||
|
||||
public UDPPinger(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public PingResult ping(InetAddress address, int count) throws IOException {
|
||||
PingResult result = new PingResult(address);
|
||||
|
||||
DatagramSocket socket = new DatagramSocket();
|
||||
socket.setSoTimeout(timeout);
|
||||
socket.connect(address, PROBE_UDP_PORT);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
DatagramPacket packet = new DatagramPacket(new byte[]{}, 0);
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
socket.send(packet);
|
||||
socket.receive(packet);
|
||||
}
|
||||
catch (PortUnreachableException e) {
|
||||
result.replyCount++;
|
||||
result.totalTime+=System.currentTimeMillis()-startTime;
|
||||
}
|
||||
catch (SocketTimeoutException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.log(Level.FINER, null, e);
|
||||
}
|
||||
}
|
||||
|
||||
socket.disconnect();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
// nothing to do here
|
||||
}
|
||||
}
|
||||
105
ipscan/src/net/azib/ipscan/exporters/CSVExporter.java
Executable file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* CSV Exporter
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class CSVExporter implements Exporter {
|
||||
|
||||
/* CSV delimeter character */
|
||||
static final char DELIMETER = ',';
|
||||
/* Delimeter escaping character (if data contains DELIMETER) */
|
||||
static final char DELIMETER_ESCAPED = '.';
|
||||
/* Newline character */
|
||||
static final String NEWLINE = System.getProperty("line.separator");
|
||||
|
||||
private Writer output;
|
||||
private boolean isAppend;
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "exporter.csv";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#getFilenameExtension()
|
||||
*/
|
||||
public String getFilenameExtension() {
|
||||
return "csv";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#setAppend(boolean)
|
||||
*/
|
||||
public void setAppend(boolean append) {
|
||||
isAppend = append;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#start(java.io.OutputStream, String)
|
||||
*/
|
||||
public void start(OutputStream outputStream, String feederInfo) {
|
||||
output = new OutputStreamWriter(outputStream);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#end()
|
||||
*/
|
||||
public void end() throws IOException {
|
||||
output.flush();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#setFetchers(String[])
|
||||
*/
|
||||
public void setFetchers(String[] fetcherNames) throws IOException {
|
||||
if (!isAppend) {
|
||||
output.write(csvSafeString(fetcherNames[0]));
|
||||
for (int i = 1; i < fetcherNames.length; i++) {
|
||||
output.write(DELIMETER);
|
||||
output.write(csvSafeString(fetcherNames[i]));
|
||||
}
|
||||
output.write(NEWLINE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#nextAdressResults(Object[])
|
||||
*/
|
||||
public void nextAdressResults(Object[] results) throws IOException {
|
||||
output.write(csvSafeString(results[0]));
|
||||
for (int i = 1; i < results.length; i++) {
|
||||
Object result = results[i];
|
||||
output.write(DELIMETER);
|
||||
output.write(csvSafeString(result));
|
||||
}
|
||||
output.write(NEWLINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a safe string to be outputted in CSV format (it doesn't contain the DELIMETER)
|
||||
*/
|
||||
String csvSafeString(Object o) {
|
||||
if (o == null)
|
||||
return "";
|
||||
return o.toString().replace(DELIMETER, DELIMETER_ESCAPED);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#clone()
|
||||
*/
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
}
|
||||
79
ipscan/src/net/azib/ipscan/exporters/ExportProcessor.java
Executable file
@ -0,0 +1,79 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.core.ScanningResult;
|
||||
import net.azib.ipscan.core.ScanningResultList;
|
||||
import net.azib.ipscan.fetchers.Fetcher;
|
||||
|
||||
/**
|
||||
* Export Processor controls the actual exporting using the provided Exporter.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ExportProcessor {
|
||||
|
||||
private Exporter exporter;
|
||||
private String fileName;
|
||||
|
||||
public ExportProcessor(Exporter exporter, String fileName) {
|
||||
this.exporter = exporter;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to execute the actual scanning process.
|
||||
* @param scanningResults the scanning results, which are available
|
||||
* @param feederInfo info about the Feeder configuration as String
|
||||
* @param resultSelector optional (can be null) - determines results for saving or skipping
|
||||
*/
|
||||
public void process(ScanningResultList scanningResults, String feederInfo, ScanningResultSelector resultSelector) {
|
||||
FileOutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = new FileOutputStream(fileName);
|
||||
|
||||
exporter.start(outputStream, feederInfo);
|
||||
|
||||
// set fetchers
|
||||
List fetchers = scanningResults.getFetchers();
|
||||
String[] fetcherNames = new String[fetchers.size()];
|
||||
int i = 0;
|
||||
for (Iterator j = fetchers.iterator(); j.hasNext(); i++) {
|
||||
fetcherNames[i] = Labels.getLabel(((Fetcher)j.next()).getLabel());
|
||||
}
|
||||
exporter.setFetchers(fetcherNames);
|
||||
|
||||
int index = 0;
|
||||
for (Iterator j = scanningResults.iterator(); j.hasNext(); index++) {
|
||||
ScanningResult scanningResult = (ScanningResult) j.next();
|
||||
if (resultSelector == null || resultSelector.isResultSelected(index, scanningResult)) {
|
||||
exporter.nextAdressResults(scanningResult.getValues().toArray());
|
||||
}
|
||||
}
|
||||
|
||||
exporter.end();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ExporterException("exporting failed", e);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
outputStream.close();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ScanningResultSelector can be implemented and passed to {@link ExportProcessor#process(ScanningResultList, String)}
|
||||
*/
|
||||
public static interface ScanningResultSelector {
|
||||
boolean isResultSelected(int index, ScanningResult result);
|
||||
}
|
||||
}
|
||||
78
ipscan/src/net/azib/ipscan/exporters/Exporter.java
Executable file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* An Exporter is a class, which is able to export scanning results into a
|
||||
* specific output format.
|
||||
*
|
||||
* This interface is callback-like. Each method of it is called when more
|
||||
* data is available for writing.
|
||||
*
|
||||
* The sequence of calling:
|
||||
* start, setFetchers, nextAddressResult, ..., end
|
||||
*
|
||||
* Exporters are created by cloning (prototype pattern).
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public interface Exporter extends Cloneable {
|
||||
|
||||
/**
|
||||
* @return label ID, representing the name of this exporter
|
||||
*/
|
||||
public String getLabel();
|
||||
|
||||
/**
|
||||
* @return the filename extension of the file type this Exporter produces (like txt, html, etc)
|
||||
*/
|
||||
public String getFilenameExtension();
|
||||
|
||||
/**
|
||||
* @param append determines whether to append to the existing file or create a new one.
|
||||
* false by default.
|
||||
*/
|
||||
public void setAppend(boolean append);
|
||||
|
||||
/**
|
||||
* Called on start of the exporting.
|
||||
* @param outputStream this OutputStream should be used to output exported data.
|
||||
* @param feederInfo summary of feeder options, which were used for this scan
|
||||
* @throws IOException
|
||||
*/
|
||||
public void start(OutputStream outputStream, String feederInfo) throws IOException;
|
||||
|
||||
/**
|
||||
* Called when no more data is available for exporting. This is the last
|
||||
* method, which is called on any exporter.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void end() throws IOException;
|
||||
|
||||
/**
|
||||
* Called after the start to provide the whole list of fetchers
|
||||
* @param fetcherNames
|
||||
* @throws IOException
|
||||
*/
|
||||
public void setFetchers(String[] fetcherNames) throws IOException;
|
||||
|
||||
/**
|
||||
* Called to provide the actual scanning results for the IP address.
|
||||
* @param results the results, returned by the Fetcher. This is an array of String
|
||||
* most of the time or objects, which provide toString() methods.
|
||||
* The IP address itself is the first element in the provided array.
|
||||
* Any element of results can be null.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void nextAdressResults(Object[] results) throws IOException;
|
||||
|
||||
/**
|
||||
* Clones the Exporter instance
|
||||
*/
|
||||
public Object clone() throws CloneNotSupportedException;
|
||||
|
||||
}
|
||||
23
ipscan/src/net/azib/ipscan/exporters/ExporterException.java
Executable file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
/**
|
||||
* Exception for throwing in case of problems in Exporters.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ExporterException extends IllegalArgumentException {
|
||||
|
||||
static final long serialVersionUID = 746237846273847L;
|
||||
|
||||
public ExporterException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ExporterException(String message, Throwable cause) {
|
||||
super(message);
|
||||
initCause(cause);
|
||||
}
|
||||
}
|
||||
58
ipscan/src/net/azib/ipscan/exporters/ExporterRegistry.java
Executable file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The registry of all Exporters.
|
||||
* It registers both plugins and builtins.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class ExporterRegistry {
|
||||
|
||||
/** All available Exporter implementations, Map of Exporter instances (prototypes) */
|
||||
private Map exporters;
|
||||
|
||||
public ExporterRegistry(Exporter[] registeredExporters) {
|
||||
exporters = new LinkedHashMap();
|
||||
|
||||
for (int i = 0; i < registeredExporters.length; i++) {
|
||||
exporters.put(registeredExporters[i].getFilenameExtension(), registeredExporters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates Exporter instances within this Registry
|
||||
*/
|
||||
public Iterator iterator() {
|
||||
return exporters.values().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new exporter instance examining the extension of the provided file name
|
||||
* @param fileName the file name (with extension)
|
||||
* @throws ExporterException in case such exporter is not registered
|
||||
*/
|
||||
public Exporter createExporter(String fileName) throws ExporterException {
|
||||
|
||||
int extensionPos = fileName.lastIndexOf('.') + 1;
|
||||
String extension = fileName.substring(extensionPos);
|
||||
|
||||
Exporter prototype = (Exporter) exporters.get(extension);
|
||||
if (prototype == null) {
|
||||
throw new ExporterException("exporter.unknown");
|
||||
}
|
||||
try {
|
||||
return (Exporter) prototype.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
// this is not possible
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
120
ipscan/src/net/azib/ipscan/exporters/IPListExporter.java
Executable file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.core.PortIterator;
|
||||
|
||||
/**
|
||||
* IP List Exporter
|
||||
* <p/>
|
||||
* Exports only IP:port info, outputting each distinct IP:port pair on separate line.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class IPListExporter implements Exporter {
|
||||
|
||||
/* CSV delimeter character */
|
||||
static final char DELIMETER = ':';
|
||||
|
||||
private int ipFetcherIndex;
|
||||
private int portsFetcherIndex;
|
||||
private PrintWriter output;
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "exporter.ipList";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#getFilenameExtension()
|
||||
*/
|
||||
public String getFilenameExtension() {
|
||||
return "lst";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#setAppend(boolean)
|
||||
*/
|
||||
public void setAppend(boolean append) {
|
||||
// no difference in this fetcher
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#start(java.io.OutputStream, String)
|
||||
*/
|
||||
public void start(OutputStream outputStream, String feederInfo) {
|
||||
output = new PrintWriter(new OutputStreamWriter(outputStream));
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#end()
|
||||
*/
|
||||
public void end() throws IOException {
|
||||
if (output.checkError()) {
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#setFetchers(String[])
|
||||
*/
|
||||
public void setFetchers(String[] fetcherNames) throws IOException {
|
||||
ipFetcherIndex = findFetcherByLabel("fetcher.ip", fetcherNames);
|
||||
portsFetcherIndex = findFetcherByLabel("fetcher.ports", fetcherNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the needed fetcher by name.
|
||||
*
|
||||
* @param label
|
||||
* @param fetcherNames
|
||||
* @return fetcher's index
|
||||
* @throws ExporterException in case fetcher is not found
|
||||
*/
|
||||
static int findFetcherByLabel(String label, String[] fetcherNames) {
|
||||
String fetcherName = Labels.getLabel(label);
|
||||
for (int i = 0; i < fetcherNames.length; i++) {
|
||||
if (fetcherName.equals(fetcherNames[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
throw new ExporterException("fetcher.notFound");
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#nextAdressResults(InetAddress, Object[])
|
||||
*/
|
||||
public void nextAdressResults(Object[] results) throws IOException {
|
||||
String address = results[ipFetcherIndex].toString();
|
||||
String portList;
|
||||
try {
|
||||
portList = results[portsFetcherIndex].toString();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore empty results
|
||||
return;
|
||||
}
|
||||
|
||||
if (portList != null) {
|
||||
for (PortIterator i = new PortIterator(portList); i.hasNext(); ) {
|
||||
output.println(address + DELIMETER + i.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#clone()
|
||||
*/
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
}
|
||||
138
ipscan/src/net/azib/ipscan/exporters/TXTExporter.java
Executable file
@ -0,0 +1,138 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.config.Version;
|
||||
|
||||
/**
|
||||
* TXT Exporter
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class TXTExporter implements Exporter {
|
||||
|
||||
/** Newline character */
|
||||
static final String NEWLINE = System.getProperty("line.separator");
|
||||
|
||||
private Writer output;
|
||||
private boolean isAppend;
|
||||
int[] padLengths;
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "exporter.txt";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#getFilenameExtension()
|
||||
*/
|
||||
public String getFilenameExtension() {
|
||||
return "txt";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#setAppend(boolean)
|
||||
*/
|
||||
public void setAppend(boolean append) {
|
||||
isAppend = append;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#start(java.io.OutputStream, String)
|
||||
*/
|
||||
public void start(OutputStream outputStream, String feederInfo) throws IOException {
|
||||
output = new OutputStreamWriter(outputStream, Labels.getLabel("encoding"));
|
||||
if (!isAppend) {
|
||||
output.write(Labels.getLabel("exporter.txt.generated"));
|
||||
println(Version.FULL_NAME);
|
||||
println(Version.WEBSITE);
|
||||
output.write(NEWLINE);
|
||||
|
||||
String scanned = Labels.getLabel("exporter.txt.scanned");
|
||||
scanned = scanned.replaceFirst("%INFO", feederInfo);
|
||||
println(scanned);
|
||||
println(DateFormat.getDateTimeInstance().format(new Date()));
|
||||
output.write(NEWLINE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#end()
|
||||
*/
|
||||
public void end() throws IOException {
|
||||
output.flush();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#setFetchers(String[])
|
||||
*/
|
||||
public void setFetchers(String[] fetcherNames) throws IOException {
|
||||
padLengths = new int[fetcherNames.length];
|
||||
for (int i = 0; i < fetcherNames.length; i++) {
|
||||
padLengths[i] = fetcherNames[i].length() * 3;
|
||||
if (!isAppend) {
|
||||
output.write(pad(fetcherNames[i], padLengths[i]));
|
||||
}
|
||||
}
|
||||
if (!isAppend) {
|
||||
output.write(NEWLINE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#nextAdressResults(InetAddress, Object[])
|
||||
*/
|
||||
public void nextAdressResults(Object[] results) throws IOException {
|
||||
output.write(pad(results[0], padLengths[0]));
|
||||
for (int i = 1; i < results.length; i++) {
|
||||
Object result = results[i];
|
||||
output.write(pad(result, padLengths[i]));
|
||||
}
|
||||
output.write(NEWLINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pads the passed string with spaces.
|
||||
* @param s
|
||||
* @param length the total returned length, minimum is 13
|
||||
*/
|
||||
String pad(Object o, int length) {
|
||||
if (length < 16)
|
||||
length = 16;
|
||||
|
||||
String s;
|
||||
if (o == null)
|
||||
s = "";
|
||||
else
|
||||
s = o.toString();
|
||||
|
||||
if (s.length() >= length) {
|
||||
return s;
|
||||
}
|
||||
return s + " ".
|
||||
substring(0, length - s.length());
|
||||
}
|
||||
|
||||
void println(String s) throws IOException {
|
||||
output.write(s);
|
||||
output.write(NEWLINE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#clone()
|
||||
*/
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
}
|
||||
120
ipscan/src/net/azib/ipscan/exporters/XMLExporter.java
Executable file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import net.azib.ipscan.config.Version;
|
||||
|
||||
/**
|
||||
* XMLExporter
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class XMLExporter implements Exporter {
|
||||
|
||||
static final String ENCODING = "UTF-8";
|
||||
|
||||
private PrintWriter output;
|
||||
private int ipFetcherIndex;
|
||||
private String[] fetcherNames;
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "exporter.xml";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#getFilenameExtension()
|
||||
*/
|
||||
public String getFilenameExtension() {
|
||||
return "xml";
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#setAppend(boolean)
|
||||
*/
|
||||
public void setAppend(boolean append) {
|
||||
if (append) {
|
||||
throw new ExporterException("xml.noAppend");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#start(java.io.OutputStream, java.lang.String)
|
||||
*/
|
||||
public void start(OutputStream outputStream, String feederInfo) throws IOException {
|
||||
output = new PrintWriter(new OutputStreamWriter(outputStream, ENCODING));
|
||||
output.println("<?xml version=\"1.0\" encoding=\"" + ENCODING + "\" standalone=\"yes\"?>");
|
||||
output.println("<!-- This file has been generated by " + Version.FULL_NAME + " -->");
|
||||
output.println("<!-- Visit the website at " + Version.WEBSITE + " -->");
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
output.println("<scanning_report time=\"" + sdf.format(new Date()) + "\">");
|
||||
|
||||
// this is a hack to extract feeder name from the feederInfo
|
||||
// this may not work with some non-standard feeders
|
||||
int colonPos = feederInfo.indexOf(':');
|
||||
String feederName = null;
|
||||
if (colonPos >= 0) {
|
||||
feederName = feederInfo.substring(0, colonPos);
|
||||
feederInfo = feederInfo.substring(colonPos + 1);
|
||||
}
|
||||
output.print("\t<feeder" + (feederName != null ? " name=\"" + feederName.trim() +"\"" : "") + ">");
|
||||
output.print("<![CDATA[" + feederInfo.trim() + "]]>");
|
||||
output.println("</feeder>");
|
||||
|
||||
output.println("\t<hosts>");
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#end()
|
||||
*/
|
||||
public void end() throws IOException {
|
||||
output.println("\t</hosts>");
|
||||
output.println("</scanning_report>");
|
||||
if (output.checkError()) {
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#setFetchers(java.lang.String[])
|
||||
*/
|
||||
public void setFetchers(String[] fetcherNames) throws IOException {
|
||||
ipFetcherIndex = IPListExporter.findFetcherByLabel("fetcher.ip", fetcherNames);
|
||||
this.fetcherNames = fetcherNames;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#nextAdressResults(java.lang.Object[])
|
||||
*/
|
||||
public void nextAdressResults(Object[] results) throws IOException {
|
||||
output.println("\t\t<host address=\"" + results[ipFetcherIndex] + "\">");
|
||||
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
if (results[i] != null) {
|
||||
output.println("\t\t\t<result name=\"" + fetcherNames[i] + "\"><![CDATA[" + results[i] + "]]></result>");
|
||||
}
|
||||
}
|
||||
|
||||
output.println("\t\t</host>");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see net.azib.ipscan.exporters.Exporter#clone()
|
||||
*/
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
}
|
||||
56
ipscan/src/net/azib/ipscan/feeders/Feeder.java
Executable file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.feeders;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* Interface of a Feeder, which is used to feed scanner with IP addresses.
|
||||
* Basically, classes implementing Feeder must provide an algorithm of
|
||||
* sequentially generating the list of scanned IP addresses.
|
||||
*
|
||||
* Feeders are created with an empty constructor only once in the applications life time.
|
||||
* All subsequent calls to the {@link #initialize(String[])} should reset the state of
|
||||
* the Feeder and begin a new "feeding" process.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public interface Feeder {
|
||||
|
||||
/**
|
||||
* @return label ID, representing the name of this Feeder
|
||||
*/
|
||||
public String getLabel();
|
||||
|
||||
/**
|
||||
* Initializes the Feeder, passing Strings as initialization parameters.
|
||||
* This method is used for resetting the state of the Feeder (similar to a constructor)
|
||||
* in both GUI and console interfaces.
|
||||
*
|
||||
* @param params the meaning and the number of these Strings depend on the implementation.
|
||||
* @return the number of consumed parameters
|
||||
*/
|
||||
public int initialize(String[] params);
|
||||
|
||||
/**
|
||||
* @return true in case there are more IPs left for processing
|
||||
*/
|
||||
public boolean hasNext();
|
||||
|
||||
/**
|
||||
* @return the next IP for processing
|
||||
*/
|
||||
public InetAddress next();
|
||||
|
||||
/**
|
||||
* @return value from 0 to 100, describing the amount of work already done
|
||||
*/
|
||||
public int getPercentageComplete();
|
||||
|
||||
/**
|
||||
* @return information about feeder's current settings.
|
||||
* Used for creation of Favorites, saving to file, etc.
|
||||
*/
|
||||
public String getInfo();
|
||||
}
|
||||
24
ipscan/src/net/azib/ipscan/feeders/FeederException.java
Executable file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.feeders;
|
||||
|
||||
/**
|
||||
* Exception for throwing in case of problems with Feeders.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class FeederException extends IllegalArgumentException {
|
||||
|
||||
static final long serialVersionUID = 746237846273847L;
|
||||
|
||||
public FeederException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public FeederException(String message, Throwable cause) {
|
||||
super(message);
|
||||
initCause(cause);
|
||||
}
|
||||
|
||||
}
|
||||
129
ipscan/src/net/azib/ipscan/feeders/FileFeeder.java
Executable file
@ -0,0 +1,129 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.feeders;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import net.azib.ipscan.core.InetAddressUtils;
|
||||
|
||||
/**
|
||||
* Feeder, taking IP addresses from text files in any format.
|
||||
* It uses regular expressions for matching of IP addresses.
|
||||
* TODO: tests!!!
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class FileFeeder implements Feeder {
|
||||
|
||||
/** Found IP address Strings are put here */
|
||||
private List foundIPAddresses;
|
||||
private Iterator foundIPAddressesIterator;
|
||||
|
||||
/** Total number of found IP addresses. Equivalent to foundIPAddresses.size(),
|
||||
* which is very ineffective in case of a LinkedList.
|
||||
*/
|
||||
private int totalAddresses;
|
||||
private int currentIndex;
|
||||
|
||||
/**
|
||||
* @see Feeder#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "feeder.file";
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the FileFeeder with required parameters
|
||||
* @see Feeder#initialize(String[])
|
||||
* @param params 1 parameter:
|
||||
* params[0] fileName
|
||||
*/
|
||||
public int initialize(String[] params) {
|
||||
initialize(params[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void initialize(String fileName) {
|
||||
try {
|
||||
initialize(new FileReader(fileName));
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
throw new FeederException("file.notExists");
|
||||
}
|
||||
}
|
||||
|
||||
void initialize(Reader reader) {
|
||||
BufferedReader fileReader = new BufferedReader(reader);
|
||||
|
||||
totalAddresses = 0;
|
||||
currentIndex = 0;
|
||||
foundIPAddresses = new LinkedList();
|
||||
try {
|
||||
String fileLine;
|
||||
while ((fileLine = fileReader.readLine()) != null) {
|
||||
Matcher matcher = InetAddressUtils.IP_ADDRESS_REGEX.matcher(fileLine);
|
||||
while (matcher.find()) {
|
||||
foundIPAddresses.add(matcher.group());
|
||||
totalAddresses++;
|
||||
}
|
||||
}
|
||||
if (totalAddresses == 0) {
|
||||
throw new FeederException("file.nothingFound");
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new FeederException("file.errorWhileReading");
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
fileReader.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore, what else to do?
|
||||
}
|
||||
}
|
||||
|
||||
foundIPAddressesIterator = foundIPAddresses.iterator();
|
||||
}
|
||||
|
||||
public int getPercentageComplete() {
|
||||
return Math.round((float)currentIndex * 100 / totalAddresses);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return foundIPAddressesIterator.hasNext();
|
||||
}
|
||||
|
||||
public InetAddress next() {
|
||||
try {
|
||||
currentIndex++;
|
||||
return InetAddress.getByName((String) foundIPAddressesIterator.next());
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
Logger.global.log(Level.WARNING, "malformedIP", e);
|
||||
throw new FeederException("malformedIP");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.feeders.Feeder#getInfo()
|
||||
*/
|
||||
public String getInfo() {
|
||||
// let's return the number of found addresses
|
||||
return Integer.toString(totalAddresses);
|
||||
}
|
||||
|
||||
}
|
||||
111
ipscan/src/net/azib/ipscan/feeders/RandomFeeder.java
Executable file
@ -0,0 +1,111 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.feeders;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import net.azib.ipscan.core.InetAddressUtils;
|
||||
|
||||
/**
|
||||
* A feeder, that generates random IP addresses.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class RandomFeeder implements Feeder {
|
||||
|
||||
SecureRandom random = new SecureRandom();
|
||||
InetAddress currentAddress;
|
||||
|
||||
byte[] prototypeBytes;
|
||||
byte[] maskBytes;
|
||||
byte[] currentBytes;
|
||||
|
||||
int addressCount;
|
||||
int currentNumber;
|
||||
|
||||
/**
|
||||
* @see Feeder#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "feeder.random";
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the RandomFeeder with required parameters
|
||||
* @see Feeder#initialize(String[])
|
||||
* @param params 3 parameters:
|
||||
* params[0] prototypeIP
|
||||
* params[1] mask
|
||||
* params[2] count
|
||||
*/
|
||||
public int initialize(String[] params) {
|
||||
try {
|
||||
initialize(params[0], params[1], Integer.parseInt(params[2]));
|
||||
return 3;
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
throw new FeederException("random.invalidCount");
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize(String prototypeIP, String mask, int count) {
|
||||
try {
|
||||
this.prototypeBytes = InetAddress.getByName(prototypeIP).getAddress();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
throw new FeederException("malformedIP");
|
||||
}
|
||||
|
||||
try {
|
||||
this.maskBytes = InetAddressUtils.parseNetmask(mask).getAddress();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
throw new FeederException("invalidNetmask");
|
||||
}
|
||||
|
||||
if (count <= 0) {
|
||||
throw new FeederException("random.invalidCount");
|
||||
}
|
||||
|
||||
this.currentNumber = 0;
|
||||
this.addressCount = count;
|
||||
this.currentBytes = new byte[prototypeBytes.length];
|
||||
}
|
||||
|
||||
public int getPercentageComplete() {
|
||||
return Math.round((float)currentNumber * 100 / addressCount);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return currentNumber < addressCount;
|
||||
}
|
||||
|
||||
public InetAddress next() {
|
||||
currentNumber++;
|
||||
random.nextBytes(currentBytes);
|
||||
try {
|
||||
InetAddressUtils.maskPrototypeAddressBytes(currentBytes, maskBytes, prototypeBytes);
|
||||
return InetAddress.getByAddress(currentBytes);
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
// this should never happen
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.feeders.Feeder#getInfo()
|
||||
*/
|
||||
public String getInfo() {
|
||||
try {
|
||||
return InetAddress.getByAddress(prototypeBytes).getHostAddress() + " / " + InetAddress.getByAddress(maskBytes).getHostAddress() + ": " + addressCount;
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
assert false : e;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
108
ipscan/src/net/azib/ipscan/feeders/RangeFeeder.java
Executable file
@ -0,0 +1,108 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.feeders;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import net.azib.ipscan.core.InetAddressUtils;
|
||||
|
||||
import org.savarese.vserv.tcpip.OctetConverter;
|
||||
|
||||
/**
|
||||
* IP Range Feeder.
|
||||
* It contains the starting and ending values, which
|
||||
* are then iterated sequentially.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class RangeFeeder implements Feeder {
|
||||
|
||||
private InetAddress startIP;
|
||||
private InetAddress endIP;
|
||||
private InetAddress originalEndIP;
|
||||
private InetAddress currentIP;
|
||||
|
||||
double percentageComplete;
|
||||
double percentageIncrement;
|
||||
|
||||
/**
|
||||
* @see Feeder#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "feeder.range";
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the RangeFeeder with required parameters
|
||||
* @see Feeder#initialize(String[])
|
||||
* @param params 2 IP addresses:
|
||||
* params[0] - startIP
|
||||
* params[1] - endIP
|
||||
*/
|
||||
public int initialize(String[] params) {
|
||||
initialize(params[0], params[1]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
public void initialize(String startIP, String endIP) {
|
||||
try {
|
||||
this.startIP = this.currentIP = InetAddress.getByName(startIP);
|
||||
this.endIP = this.originalEndIP = InetAddress.getByName(endIP);
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
throw new FeederException("malformedIP");
|
||||
}
|
||||
if (InetAddressUtils.greaterThan(this.startIP, this.endIP)) {
|
||||
throw new FeederException("range.greaterThan");
|
||||
}
|
||||
initPercentageIncrement();
|
||||
this.endIP = InetAddressUtils.increment(this.endIP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initalizes fields, used for computation of percentage of completion.
|
||||
*/
|
||||
private void initPercentageIncrement() {
|
||||
// Warning: IPv4 specific code!
|
||||
long rawEndIP = OctetConverter.octetsToInt(this.endIP.getAddress());
|
||||
long rawStartIP = OctetConverter.octetsToInt(this.startIP.getAddress());
|
||||
// make 32-bit usigned values
|
||||
rawEndIP = rawEndIP >= 0 ? rawEndIP : rawEndIP + Integer.MAX_VALUE;
|
||||
rawStartIP = rawStartIP >= 0 ? rawStartIP : rawStartIP + Integer.MAX_VALUE;
|
||||
// compute 1% of the whole range
|
||||
percentageIncrement = 100.0/(rawEndIP - rawStartIP + 1);
|
||||
percentageComplete = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.feeders.Feeder#hasNext()
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
// equals() is faster than greaterThan()
|
||||
return !currentIP.equals(endIP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.feeders.Feeder#next()
|
||||
*/
|
||||
public InetAddress next() {
|
||||
percentageComplete += percentageIncrement;
|
||||
InetAddress prevIP = this.currentIP;
|
||||
this.currentIP = InetAddressUtils.increment(prevIP);
|
||||
return prevIP;
|
||||
}
|
||||
|
||||
public int getPercentageComplete() {
|
||||
return (int)Math.round(percentageComplete);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.feeders.Feeder#getInfo()
|
||||
*/
|
||||
public String getInfo() {
|
||||
// let's return the range
|
||||
return startIP.getHostAddress() + " - " + originalEndIP.getHostAddress();
|
||||
}
|
||||
}
|
||||
67
ipscan/src/net/azib/ipscan/feeders/SmartTextFeeder.java
Executable file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.feeders;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import net.azib.ipscan.core.InetAddressUtils;
|
||||
|
||||
import org.savarese.vserv.tcpip.OctetConverter;
|
||||
|
||||
/**
|
||||
* Smart text feeder for advenced users.
|
||||
*
|
||||
* TODO: implement SmartTextFeeder to accept text, e.g.
|
||||
* 127.0.0.1-255
|
||||
* 127.0-10.13-15.1
|
||||
* 127.0.0.1/24
|
||||
*
|
||||
* Warning: IPv4-specific!
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class SmartTextFeeder implements Feeder {
|
||||
|
||||
private String netmask;
|
||||
|
||||
public String getLabel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int initialize(String[] params) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void initialize(String text) {
|
||||
// remove all whitespace
|
||||
text = text.replaceAll("\\w+", "");
|
||||
|
||||
// extract netmask
|
||||
int slashPos = text.indexOf('/');
|
||||
if (slashPos >= 0) {
|
||||
netmask = text.substring(slashPos+1);
|
||||
text = text.substring(0, slashPos);
|
||||
}
|
||||
|
||||
String[] tokens = text.split("\\.");
|
||||
// TODO: use port list parsing code here
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public InetAddress next() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getPercentageComplete() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getInfo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
39
ipscan/src/net/azib/ipscan/fetchers/CommentFetcher.java
Executable file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* This file is a part of Angry IP Scanner source code,
|
||||
* see http://www.azib.net/ for more information.
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
|
||||
/**
|
||||
* A fetcher for displaying of user-defined comments about every IP address.
|
||||
*
|
||||
* TODO: implement CommentFetcher
|
||||
* TODO: make an editor for comments
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class CommentFetcher implements Fetcher {
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.fetchers.Fetcher#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "fetcher.ip";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.fetchers.Fetcher#scan(net.azib.ipscan.core.ScanningSubject)
|
||||
*/
|
||||
public Object scan(ScanningSubject subject) {
|
||||
return "a dummy comment!!!";
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
}
|
||||
|
||||
}
|
||||
50
ipscan/src/net/azib/ipscan/fetchers/Fetcher.java
Executable file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* This file is a part of Angry IP Scanner source code,
|
||||
* see http://www.azib.net/ for more information.
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.core.NotAvailableValue;
|
||||
import net.azib.ipscan.core.NotScannedValue;
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
|
||||
/**
|
||||
* Interface of all IP Fetchers.
|
||||
*
|
||||
* Fetcher is responsible for gathering a certain type of
|
||||
* information about the provided scanning subject
|
||||
* (in GUI terms, Fetcher is a column in the results list).
|
||||
*
|
||||
* Fetchers do the actual information fetching about each
|
||||
* scanned IP address.
|
||||
*
|
||||
* Instances of this classes are shared among all the threads,
|
||||
* so implementations must be thread safe and stateless.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public interface Fetcher extends Cloneable {
|
||||
|
||||
/**
|
||||
* @return label ID, representing the name of this fetcher
|
||||
*/
|
||||
public String getLabel();
|
||||
|
||||
/**
|
||||
* Does the actual fetching.
|
||||
* @param subject the scanning subject, containing an IP address
|
||||
* @return the fetched data (a String in most cases), null in case of any error.
|
||||
* Special values may also be returned, such as {@link NotAvailableValue} or {@link NotScannedValue}
|
||||
*/
|
||||
public Object scan(ScanningSubject subject);
|
||||
|
||||
/**
|
||||
* Called before scanning has started to do any intialization stuff
|
||||
*/
|
||||
public void init();
|
||||
|
||||
/**
|
||||
* Called after the scanning has been completed to do any cleanup needed
|
||||
*/
|
||||
public void cleanup();
|
||||
}
|
||||
19
ipscan/src/net/azib/ipscan/fetchers/FetcherException.java
Executable file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
/**
|
||||
* FetcherException
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class FetcherException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FetcherException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
46
ipscan/src/net/azib/ipscan/fetchers/FetcherRegistry.java
Executable file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* FetcherRegistry
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public interface FetcherRegistry {
|
||||
|
||||
/**
|
||||
* @return a List of all registered Fetchers
|
||||
*/
|
||||
public Collection getRegisteredFetchers();
|
||||
|
||||
/**
|
||||
* @return a List of selected Fetchers only
|
||||
*/
|
||||
public Collection getSelectedFetchers();
|
||||
|
||||
/**
|
||||
* Searches for selected fetcher with the given label
|
||||
* @param label
|
||||
* @return the index, if found, or -1
|
||||
*/
|
||||
public int getSelectedFetcherIndex(String label);
|
||||
|
||||
/**
|
||||
* Updates the list, retaining only items that are passed in the array.
|
||||
* The order of elements will be the same as in the array.
|
||||
*
|
||||
* @param names
|
||||
*/
|
||||
public void updateSelectedFetchers(String[] names);
|
||||
|
||||
/**
|
||||
* Adds a listener to observe FetcherRegistry events, like modification of selected fetchers.
|
||||
* @param listener
|
||||
*/
|
||||
public void addListener(FetcherRegistryUpdateListener listener);
|
||||
|
||||
}
|
||||
80
ipscan/src/net/azib/ipscan/fetchers/FetcherRegistryImpl.java
Executable file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Fetcher Registry singleton class.
|
||||
* Actually, it registers both plugins and builtins.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class FetcherRegistryImpl implements FetcherRegistry {
|
||||
|
||||
/** All available Fetcher implementations, List of Fetcher instances */
|
||||
private List registeredFetchers;
|
||||
/** Selected for scanning Fetcher implementations, keys are fetcher labels, values are Fetcher instances */
|
||||
private Map selectedFetchers;
|
||||
/** A collection of update listeners - observers of FetcherRegistry */
|
||||
private List updateListeners = new ArrayList();
|
||||
|
||||
public FetcherRegistryImpl(Fetcher[] registeredFetchers) {
|
||||
this.registeredFetchers = Arrays.asList(registeredFetchers);
|
||||
this.registeredFetchers = Collections.unmodifiableList(this.registeredFetchers);
|
||||
|
||||
// TODO: this should be loaded from config as well as reasonable defaults should be made
|
||||
this.selectedFetchers = new LinkedHashMap();
|
||||
for (Iterator i = this.registeredFetchers.iterator(); i.hasNext();) {
|
||||
Fetcher fetcher = (Fetcher) i.next();
|
||||
this.selectedFetchers.put(fetcher.getLabel(), fetcher);
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(FetcherRegistryUpdateListener listener) {
|
||||
updateListeners.add(listener);
|
||||
}
|
||||
|
||||
public Collection getRegisteredFetchers() {
|
||||
return registeredFetchers;
|
||||
}
|
||||
|
||||
public Collection getSelectedFetchers() {
|
||||
return selectedFetchers.values();
|
||||
}
|
||||
|
||||
public int getSelectedFetcherIndex(String label) {
|
||||
int index = -1;
|
||||
for (Iterator i = selectedFetchers.values().iterator(); i.hasNext();) {
|
||||
if (((Fetcher)i.next()).getLabel().equals(label))
|
||||
break;
|
||||
index++;
|
||||
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public void updateSelectedFetchers(String[] labels) {
|
||||
// rebuild the map (to recreate the new order of elements)
|
||||
Map newList = new LinkedHashMap();
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
newList.put(labels[i], selectedFetchers.get(labels[i]));
|
||||
}
|
||||
selectedFetchers = newList;
|
||||
|
||||
// invorm observers
|
||||
for (Iterator i = updateListeners.iterator(); i.hasNext();) {
|
||||
FetcherRegistryUpdateListener listener = (FetcherRegistryUpdateListener) i.next();
|
||||
listener.handleUpdateOfSelectedFetchers(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
20
ipscan/src/net/azib/ipscan/fetchers/FetcherRegistryUpdateListener.java
Executable file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
/**
|
||||
* FetcherRegistryUpdateListener.
|
||||
* Implement this interface if you need to react to FetcherRegistry updates.
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public interface FetcherRegistryUpdateListener {
|
||||
|
||||
/**
|
||||
* This method is called when the list of selected Fetchers was changed.
|
||||
* @param fetcherRegistry
|
||||
*/
|
||||
void handleUpdateOfSelectedFetchers(FetcherRegistry fetcherRegistry);
|
||||
|
||||
}
|
||||
27
ipscan/src/net/azib/ipscan/fetchers/FilteredPortsFetcher.java
Executable file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
|
||||
/**
|
||||
* FilteredPortsFetcher uses the scanning results of PortsFetcher to display filtered ports.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class FilteredPortsFetcher extends PortsFetcher {
|
||||
|
||||
public String getLabel() {
|
||||
return "fetcher.ports.filtered";
|
||||
}
|
||||
|
||||
public Object scan(ScanningSubject subject) {
|
||||
scanPorts(subject);
|
||||
Set filteredPorts = getFilteredPorts(subject);
|
||||
return filteredPorts.size() > 0 ? portListToRange(filteredPorts, displayAsRanges) : null;
|
||||
}
|
||||
|
||||
}
|
||||
38
ipscan/src/net/azib/ipscan/fetchers/HostnameFetcher.java
Executable file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This file is a part of Angry IP Scanner source code,
|
||||
* see http://www.azib.net/ for more information.
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
|
||||
/**
|
||||
* HostnameFetcher retrieves hostnames of IP addresses by reverse DNS lookups.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class HostnameFetcher implements Fetcher {
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.fetchers.Fetcher#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "fetcher.hostname";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.fetchers.Fetcher#scan(net.azib.ipscan.core.ScanningSubject)
|
||||
*/
|
||||
public Object scan(ScanningSubject subject) {
|
||||
String hostname = subject.getIPAddress().getCanonicalHostName();
|
||||
// return the returned hostname only if it is not the same as the IP address (this is how the above method works)
|
||||
return subject.getIPAddress().getHostAddress().equals(hostname) ? null : hostname;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
}
|
||||
|
||||
}
|
||||
37
ipscan/src/net/azib/ipscan/fetchers/IPFetcher.java
Executable file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* This file is a part of Angry IP Scanner source code,
|
||||
* see http://www.azib.net/ for more information.
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
|
||||
/**
|
||||
* Dummy fetcher, which is able to return the textual representation
|
||||
* of the passed IP address.
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class IPFetcher implements Fetcher {
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.fetchers.Fetcher#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return "fetcher.ip";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.azib.ipscan.fetchers.Fetcher#scan(net.azib.ipscan.core.ScanningSubject)
|
||||
*/
|
||||
public Object scan(ScanningSubject subject) {
|
||||
return subject.getIPAddress().getHostAddress();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
}
|
||||
|
||||
}
|
||||
19
ipscan/src/net/azib/ipscan/fetchers/PacketLossFetcher.java
Executable file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.core.net.PingerRegistry;
|
||||
|
||||
/**
|
||||
* TODO PacketLossFetcher
|
||||
*
|
||||
* @author anton
|
||||
*/
|
||||
public class PacketLossFetcher extends PingFetcher {
|
||||
|
||||
public PacketLossFetcher(PingerRegistry pingerRegistry) {
|
||||
super(pingerRegistry);
|
||||
}
|
||||
|
||||
}
|
||||