Skip to content

Commit

Permalink
Merge pull request #58 from compscidr/jason/logips-update
Browse files Browse the repository at this point in the history
Update with logips library
  • Loading branch information
compscidr authored Nov 20, 2024
2 parents f489dc6 + 6c0b978 commit 8e9a3bc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 40 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ icmp_common = { module = "com.jasonernst.icmp:icmp_common", version.ref = "icmp"
icmp_android = { module = "com.jasonernst.icmp:icmp_android", version.ref = "icmp" }
logback-android = { module = "com.github.tony19:logback-android", version.ref = "logback-android" }
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback-classic" }
logips = { module = "com.jasonernst.logips:logips", version="0.0.1" }
material = { module = "com.google.android.material:material", version.ref = "material" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
Expand Down
1 change: 1 addition & 0 deletions packetdumper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
testImplementation(libs.bundles.test)
testRuntimeOnly(libs.junit.jupiter.engine)
testImplementation(libs.logback.classic)
implementation(libs.logips)
}

version = "0.0.0-SNAPSHOT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory
import java.io.BufferedOutputStream
import java.net.ServerSocket
import java.net.Socket
import java.net.SocketException
import java.nio.ByteBuffer
import java.util.Collections
import java.util.concurrent.atomic.AtomicBoolean
Expand All @@ -28,7 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean
*/
class PcapNgTcpServerPacketDumper(
private val listenPort: Int = DEFAULT_PORT,
private val isSimple: Boolean = true,
private val isSimple: Boolean = false,
private val callback: ConnectedUsersChangedCallback? = null,
) : AbstractServerPacketDumper() {
private val logger = LoggerFactory.getLogger(javaClass)
Expand Down Expand Up @@ -58,7 +57,7 @@ class PcapNgTcpServerPacketDumper(
return@Thread
}
logger.trace("WiresharkTcpDump listening on {}", socket!!.localSocketAddress)
logAllIPAddresses()
LogIp.logAllIPAddresses()
isRunning.set(true)

while (isRunning.get()) {
Expand Down Expand Up @@ -178,41 +177,4 @@ class PcapNgTcpServerPacketDumper(
private fun issueCallback() {
callback?.onConnectedUsersChanged(connectionQueue.map { it.remoteSocketAddress.toString() })
}

private fun logAllIPAddresses(
excludeInterfaces: List<String> = listOf("bump", "docker", "virbr", "veth", "tailscale", "dummy", "tun"),
) {
try {
val interfaces = java.net.NetworkInterface.getNetworkInterfaces()
if (interfaces == null) {
logger.error("No network interfaces found")
return
}
for (networkInterface in interfaces) {
var excluded = false
for (excludeInterface in excludeInterfaces) {
if (networkInterface.displayName.contains(excludeInterface)) {
excluded = true
break
}
}
if (excluded) {
continue
}
if (networkInterface.isUp.not()) {
continue
}
val addresses = networkInterface.inetAddresses.toList()
if (addresses.isEmpty()) {
continue
}
logger.trace("Network Interface: ${networkInterface.name}")
for (inetAddress in addresses) {
logger.trace(" IP Address: ${inetAddress.hostAddress}")
}
}
} catch (e: SocketException) {
logger.error("Error getting network interfaces", e)
}
}
}

0 comments on commit 8e9a3bc

Please sign in to comment.